LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmith_openapi_client_modelsBaseModelto_json
Methodā—Since v0.8

to_json

Copy
to_json(
  self,
  *,
  indent: int | None = 2,
  use_api_names: bool =
View source on GitHub
True
,
exclude_unset
:
bool
=
True
,
exclude_defaults
:
bool
=
False
,
exclude_none
:
bool
=
False
,
warnings
:
bool
=
True
)
->
str

Parameters

NameTypeDescription
indentint | None
Default:2

Indentation to use in the JSON output. If None is passed, the output will be compact. Defaults to 2

use_api_namesbool
Default:True

Whether to use the key that the API responded with or the property name. Defaults to True.

exclude_unsetbool
Default:True

Whether to exclude fields that have not been explicitly set.

exclude_defaultsbool
Default:False
exclude_nonebool
Default:False
warningsbool
Default:True

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).

Whether to exclude fields that have the default value.

Whether to exclude fields that have a value of None.

Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.