MCPcopy Create free account
hub / github.com/OpenRouterTeam/python-sdk / marshal_json

Function marshal_json

src/openrouter/utils/serializers.py:134–151  ·  view source on GitHub ↗
(val, typ)

Source from the content-addressed store, hash-verified

132
133
134def marshal_json(val, typ):
135 if is_nullable(typ) and val is None:
136 return "null"
137
138 marshaller = create_model(
139 "Marshaller",
140 body=(typ, ...),
141 __config__=ConfigDict(populate_by_name=True, arbitrary_types_allowed=True),
142 )
143
144 m = marshaller(body=val)
145
146 d = m.model_dump(by_alias=True, mode="json", exclude_none=True)
147
148 if len(d) == 0:
149 return ""
150
151 return json.dumps(d[next(iter(d))], separators=(",", ":"))
152
153
154def is_nullable(field):

Callers 4

serialize_multipart_formFunction · 0.85
serialize_form_dataFunction · 0.85
_get_serialized_paramsFunction · 0.85
serialize_request_bodyFunction · 0.85

Calls 1

is_nullableFunction · 0.85

Tested by

no test coverage detected