MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / json_safe

Function json_safe

src/opencode_ai/_utils/_utils.py:409–422  ·  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

407
408
409def json_safe(data: object) -> object:
410 """Translates a mapping / sequence recursively in the same fashion
411 as `pydantic` v2's `model_dump(mode="json")`.
412 """
413 if is_mapping(data):
414 return {json_safe(key): json_safe(value) for key, value in data.items()}
415
416 if is_iterable(data) and not isinstance(data, (str, bytes, bytearray)):
417 return [json_safe(item) for item in data]
418
419 if isinstance(data, (datetime, date)):
420 return data.isoformat()
421
422 return data

Callers 1

model_dumpMethod · 0.85

Calls 2

is_mappingFunction · 0.85
is_iterableFunction · 0.85

Tested by

no test coverage detected