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

Method to_json

src/opencode_ai/_models.py:137–170  ·  view source on GitHub ↗

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 e

(
        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,
    )

Source from the content-addressed store, hash-verified

135 )
136
137 def to_json(
138 self,
139 *,
140 indent: int | None = 2,
141 use_api_names: bool = True,
142 exclude_unset: bool = True,
143 exclude_defaults: bool = False,
144 exclude_none: bool = False,
145 warnings: bool = True,
146 ) -> str:
147 """Generates a JSON string representing this model as it would be received from or sent to the API (but with indentation).
148
149 By default, fields that were not set by the API will not be included,
150 and keys will match the API response, *not* the property names from the model.
151
152 For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
153 the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).
154
155 Args:
156 indent: Indentation to use in the JSON output. If `None` is passed, the output will be compact. Defaults to `2`
157 use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
158 exclude_unset: Whether to exclude fields that have not been explicitly set.
159 exclude_defaults: Whether to exclude fields that have the default value.
160 exclude_none: Whether to exclude fields that have a value of `None`.
161 warnings: Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.
162 """
163 return self.model_dump_json(
164 indent=indent,
165 by_alias=use_api_names,
166 exclude_unset=exclude_unset,
167 exclude_defaults=exclude_defaults,
168 exclude_none=exclude_none,
169 warnings=warnings,
170 )
171
172 @override
173 def __str__(self) -> str:

Callers 1

test_to_jsonFunction · 0.80

Calls 1

model_dump_jsonMethod · 0.95

Tested by 1

test_to_jsonFunction · 0.64