Home / Function/ _parse_json() — langchain Function Reference

_parse_json() — langchain Function Reference

Architecture documentation for the _parse_json() function in json.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9e969ef0_5395_65ea_99a0_e06563a3e201["_parse_json()"]
  20a5fe84_8249_f1df_53f0_7f22870f123f["json.py"]
  9e969ef0_5395_65ea_99a0_e06563a3e201 -->|defined in| 20a5fe84_8249_f1df_53f0_7f22870f123f
  0674c31d_4e25_0239_78af_91c5993e3cb3["parse_json_markdown()"]
  0674c31d_4e25_0239_78af_91c5993e3cb3 -->|calls| 9e969ef0_5395_65ea_99a0_e06563a3e201
  9e969ef0_5395_65ea_99a0_e06563a3e201["_parse_json()"]
  9e969ef0_5395_65ea_99a0_e06563a3e201 -->|calls| 9e969ef0_5395_65ea_99a0_e06563a3e201
  9e969ef0_5395_65ea_99a0_e06563a3e201["_parse_json()"]
  9e969ef0_5395_65ea_99a0_e06563a3e201 -->|calls| 9e969ef0_5395_65ea_99a0_e06563a3e201
  f4a1a21e_8139_ba95_7fed_27593c884279["_custom_parser()"]
  9e969ef0_5395_65ea_99a0_e06563a3e201 -->|calls| f4a1a21e_8139_ba95_7fed_27593c884279
  style 9e969ef0_5395_65ea_99a0_e06563a3e201 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/json.py lines 169–191

def _parse_json(
    json_str: str, *, parser: Callable[[str], Any] = parse_partial_json
) -> Any:
    """Parse a JSON string, handling special characters and whitespace.

    Strips whitespace, newlines, and backticks from the start and end of the string,
    then processes special characters before parsing.

    Args:
        json_str: The JSON string to parse.
        parser: Optional custom parser function.

    Returns:
        Parsed JSON object.
    """
    # Strip whitespace,newlines,backtick from the start and end
    json_str = json_str.strip(_json_strip_chars)

    # handle newlines and other special characters inside the returned value
    json_str = _custom_parser(json_str)

    # Parse the JSON string into a Python dictionary
    return parser(json_str)

Domain

Subdomains

Frequently Asked Questions

What does _parse_json() do?
_parse_json() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/json.py.
Where is _parse_json() defined?
_parse_json() is defined in libs/core/langchain_core/utils/json.py at line 169.
What does _parse_json() call?
_parse_json() calls 2 function(s): _custom_parser, _parse_json.
What calls _parse_json()?
_parse_json() is called by 2 function(s): _parse_json, parse_json_markdown.

Analyze Your Own Codebase

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

Try Supermodel Free