Home / Function/ to_json() — anthropic-sdk-python Function Reference

to_json() — anthropic-sdk-python Function Reference

Architecture documentation for the to_json() function in _models.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  6f82b0a7_6591_72e0_8921_bedf8e6504de["to_json()"]
  17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"]
  6f82b0a7_6591_72e0_8921_bedf8e6504de -->|defined in| 17ce5647_6f06_0676_a4a5_e378a3f57cb1
  style 6f82b0a7_6591_72e0_8921_bedf8e6504de fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_models.py lines 167–200

    def to_json(
        self,
        *,
        indent: int | None = 2,
        use_api_names: bool = True,
        exclude_unset: bool = True,
        exclude_defaults: bool = False,
        exclude_none: bool = False,
        warnings: bool = True,
    ) -> str:
        """Generates a JSON string representing this model as it would be received from or sent to the API (but with indentation).

        By default, fields that were not set by the API will not be included,
        and keys will match the API response, *not* the property names from the model.

        For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
        the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).

        Args:
            indent: Indentation to use in the JSON output. If `None` is passed, the output will be compact. Defaults to `2`
            use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
            exclude_unset: Whether to exclude fields that have not been explicitly set.
            exclude_defaults: Whether to exclude fields that have the default value.
            exclude_none: Whether to exclude fields that have a value of `None`.
            warnings: Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.
        """
        return self.model_dump_json(
            indent=indent,
            by_alias=use_api_names,
            exclude_unset=exclude_unset,
            exclude_defaults=exclude_defaults,
            exclude_none=exclude_none,
            warnings=warnings,
        )

Subdomains

Frequently Asked Questions

What does to_json() do?
to_json() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_models.py.
Where is to_json() defined?
to_json() is defined in src/anthropic/_models.py at line 167.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free