test_to_json() — anthropic-sdk-python Function Reference
Architecture documentation for the test_to_json() function in test_models.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD e06ba64e_7689_a113_6e7e_e6b6d437d564["test_to_json()"] 7872e60b_4210_5600_119f_c5d08c52091e["test_models.py"] e06ba64e_7689_a113_6e7e_e6b6d437d564 -->|defined in| 7872e60b_4210_5600_119f_c5d08c52091e style e06ba64e_7689_a113_6e7e_e6b6d437d564 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_models.py lines 575–600
def test_to_json() -> None:
class Model(BaseModel):
foo: Optional[str] = Field(alias="FOO", default=None)
m = Model(FOO="hello")
assert json.loads(m.to_json()) == {"FOO": "hello"}
assert json.loads(m.to_json(use_api_names=False)) == {"foo": "hello"}
if PYDANTIC_V1:
assert m.to_json(indent=None) == '{"FOO": "hello"}'
else:
assert m.to_json(indent=None) == '{"FOO":"hello"}'
m2 = Model()
assert json.loads(m2.to_json()) == {}
assert json.loads(m2.to_json(exclude_unset=False)) == {"FOO": None}
assert json.loads(m2.to_json(exclude_unset=False, exclude_none=True)) == {}
assert json.loads(m2.to_json(exclude_unset=False, exclude_defaults=True)) == {}
m3 = Model(FOO=None)
assert json.loads(m3.to_json()) == {"FOO": None}
assert json.loads(m3.to_json(exclude_none=True)) == {}
if PYDANTIC_V1:
with pytest.raises(ValueError, match="warnings is only supported in Pydantic v2"):
m.to_json(warnings=False)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_to_json() do?
test_to_json() is a function in the anthropic-sdk-python codebase, defined in tests/test_models.py.
Where is test_to_json() defined?
test_to_json() is defined in tests/test_models.py at line 575.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free