to_json() — langchain Function Reference
Architecture documentation for the to_json() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 436d3a55_ec61_7819_2986_6664246558c2["to_json()"] 646f3bb5_a594_563e_cfbf_e18bdc9efb90["Graph"] 436d3a55_ec61_7819_2986_6664246558c2 -->|defined in| 646f3bb5_a594_563e_cfbf_e18bdc9efb90 06f839e9_c953_ef45_72b3_7929f39522ed["is_uuid()"] 436d3a55_ec61_7819_2986_6664246558c2 -->|calls| 06f839e9_c953_ef45_72b3_7929f39522ed 34379327_05b8_129e_590e_63948fab3a3d["node_data_json()"] 436d3a55_ec61_7819_2986_6664246558c2 -->|calls| 34379327_05b8_129e_590e_63948fab3a3d style 436d3a55_ec61_7819_2986_6664246558c2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 264–299
def to_json(self, *, with_schemas: bool = False) -> dict[str, list[dict[str, Any]]]:
"""Convert the graph to a JSON-serializable format.
Args:
with_schemas: Whether to include the schemas of the nodes if they are
Pydantic models.
Returns:
A dictionary with the nodes and edges of the graph.
"""
stable_node_ids = {
node.id: i if is_uuid(node.id) else node.id
for i, node in enumerate(self.nodes.values())
}
edges: list[dict[str, Any]] = []
for edge in self.edges:
edge_dict = {
"source": stable_node_ids[edge.source],
"target": stable_node_ids[edge.target],
}
if edge.data is not None:
edge_dict["data"] = edge.data # type: ignore[assignment]
if edge.conditional:
edge_dict["conditional"] = True
edges.append(edge_dict)
return {
"nodes": [
{
"id": stable_node_ids[node.id],
**node_data_json(node, with_schemas=with_schemas),
}
for node in self.nodes.values()
],
"edges": edges,
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does to_json() do?
to_json() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is to_json() defined?
to_json() is defined in libs/core/langchain_core/runnables/graph.py at line 264.
What does to_json() call?
to_json() calls 2 function(s): is_uuid, node_data_json.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free