json_safe() — anthropic-sdk-python Function Reference
Architecture documentation for the json_safe() function in _utils.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 1033ac62_5341_be31_0a72_cd091ba0d38f["json_safe()"] 875202ec_3744_577d_9ec4_ed9fbc6aaf41["_utils.py"] 1033ac62_5341_be31_0a72_cd091ba0d38f -->|defined in| 875202ec_3744_577d_9ec4_ed9fbc6aaf41 b41b21ba_47c5_2c24_a6d6_d106399b3c57["is_mapping()"] 1033ac62_5341_be31_0a72_cd091ba0d38f -->|calls| b41b21ba_47c5_2c24_a6d6_d106399b3c57 6136e8f7_248c_4449_ec8e_4711c4295b45["is_iterable()"] 1033ac62_5341_be31_0a72_cd091ba0d38f -->|calls| 6136e8f7_248c_4449_ec8e_4711c4295b45 style 1033ac62_5341_be31_0a72_cd091ba0d38f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/_utils/_utils.py lines 408–421
def json_safe(data: object) -> object:
"""Translates a mapping / sequence recursively in the same fashion
as `pydantic` v2's `model_dump(mode="json")`.
"""
if is_mapping(data):
return {json_safe(key): json_safe(value) for key, value in data.items()}
if is_iterable(data) and not isinstance(data, (str, bytes, bytearray)):
return [json_safe(item) for item in data]
if isinstance(data, (datetime, date)):
return data.isoformat()
return data
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does json_safe() do?
json_safe() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_utils/_utils.py.
Where is json_safe() defined?
json_safe() is defined in src/anthropic/_utils/_utils.py at line 408.
What does json_safe() call?
json_safe() calls 2 function(s): is_iterable, is_mapping.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free