MCPcopy
hub / github.com/openai/openai-python / json_safe

Function json_safe

src/openai/_utils/_utils.py:424–437  ·  view source on GitHub ↗

Translates a mapping / sequence recursively in the same fashion as `pydantic` v2's `model_dump(mode="json")`.

(data: object)

Source from the content-addressed store, hash-verified

422
423
424def json_safe(data: object) -> object:
425 """Translates a mapping / sequence recursively in the same fashion
426 as `pydantic` v2's `model_dump(mode="json")`.
427 """
428 if is_mapping(data):
429 return {json_safe(key): json_safe(value) for key, value in data.items()}
430
431 if is_iterable(data) and not isinstance(data, (str, bytes, bytearray)):
432 return [json_safe(item) for item in data]
433
434 if isinstance(data, (datetime, date)):
435 return data.isoformat()
436
437 return data
438
439
440def is_azure_client(client: object) -> TypeGuard[AzureOpenAI]:

Callers 1

model_dumpMethod · 0.85

Calls 3

is_mappingFunction · 0.85
is_iterableFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected