MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / model_dump_json

Method model_dump_json

src/anthropic/_models.py:364–422  ·  view source on GitHub ↗

Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json Generates a JSON representation of the model using Pydantic's `to_json` method. Args: indent: Indentation to use in the JSON output. If None is passed, the output will be

(
            self,
            *,
            indent: int | None = None,
            ensure_ascii: bool = False,
            include: IncEx | None = None,
            exclude: IncEx | None = None,
            context: Any | None = None,
            by_alias: bool | None = None,
            exclude_unset: bool = False,
            exclude_defaults: bool = False,
            exclude_none: bool = False,
            exclude_computed_fields: bool = False,
            round_trip: bool = False,
            warnings: bool | Literal["none", "warn", "error"] = True,
            fallback: Callable[[Any], Any] | None = None,
            serialize_as_any: bool = False,
        )

Source from the content-addressed store, hash-verified

362
363 @override
364 def model_dump_json(
365 self,
366 *,
367 indent: int | None = None,
368 ensure_ascii: bool = False,
369 include: IncEx | None = None,
370 exclude: IncEx | None = None,
371 context: Any | None = None,
372 by_alias: bool | None = None,
373 exclude_unset: bool = False,
374 exclude_defaults: bool = False,
375 exclude_none: bool = False,
376 exclude_computed_fields: bool = False,
377 round_trip: bool = False,
378 warnings: bool | Literal["none", "warn", "error"] = True,
379 fallback: Callable[[Any], Any] | None = None,
380 serialize_as_any: bool = False,
381 ) -> str:
382 """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
383
384 Generates a JSON representation of the model using Pydantic's `to_json` method.
385
386 Args:
387 indent: Indentation to use in the JSON output. If None is passed, the output will be compact.
388 include: Field(s) to include in the JSON output. Can take either a string or set of strings.
389 exclude: Field(s) to exclude from the JSON output. Can take either a string or set of strings.
390 by_alias: Whether to serialize using field aliases.
391 exclude_unset: Whether to exclude fields that have not been explicitly set.
392 exclude_defaults: Whether to exclude fields that have the default value.
393 exclude_none: Whether to exclude fields that have a value of `None`.
394 round_trip: Whether to use serialization/deserialization between JSON and class instance.
395 warnings: Whether to show any warnings that occurred during serialization.
396
397 Returns:
398 A JSON string representation of the model.
399 """
400 if round_trip != False:
401 raise ValueError("round_trip is only supported in Pydantic v2")
402 if warnings != True:
403 raise ValueError("warnings is only supported in Pydantic v2")
404 if context is not None:
405 raise ValueError("context is only supported in Pydantic v2")
406 if serialize_as_any != False:
407 raise ValueError("serialize_as_any is only supported in Pydantic v2")
408 if fallback is not None:
409 raise ValueError("fallback is only supported in Pydantic v2")
410 if ensure_ascii != False:
411 raise ValueError("ensure_ascii is only supported in Pydantic v2")
412 if exclude_computed_fields != False:
413 raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
414 return super().json( # type: ignore[reportDeprecated]
415 indent=indent,
416 include=include,
417 exclude=exclude,
418 by_alias=by_alias if by_alias is not None else False,
419 exclude_unset=exclude_unset,
420 exclude_defaults=exclude_defaults,
421 exclude_none=exclude_none,

Callers 9

to_jsonMethod · 0.95
model_jsonFunction · 0.80
assert_message_matchesFunction · 0.80
mainFunction · 0.80
images.pyFile · 0.80
tools.pyFile · 0.80
web_search.pyFile · 0.80
bedrock.pyFile · 0.80

Calls 1

jsonMethod · 0.45