parse_partial_json

Function parse_partial_json 

Source
pub fn parse_partial_json(
    s: &str,
    strict: bool,
) -> Result<Value, JsonParseError>
Expand description

Parse a JSON string that may be missing closing braces.

This function attempts to parse a JSON string that may be incomplete, such as from a streaming LLM response.

§Arguments

  • s - The JSON string to parse.
  • strict - Whether to use strict parsing (disallow control characters in strings).

§Returns

The parsed JSON value, or an error if parsing fails.

§Example

use agent_chain_core::utils::json::parse_partial_json;

let result = parse_partial_json(r#"{"key": "value"}"#, false);
assert!(result.is_ok());