Skip to main content

extract_json_array

Function extract_json_array 

Source
pub fn extract_json_array(json_str: &str, path: &str) -> Result<Vec<Value>>
Expand description

Extract a JSON array from a JSON string using a simple path expression.

Supports paths like $.field_name or $.field.nested. Returns the array found at the given path.

Resilient to mixed-text input (e.g. LLM agent output with natural language before/after JSON). Tries in order:

  1. Parse the entire string as JSON
  2. Extract from a fenced code block (json ... )
  3. Scan for the first { or [ and try parsing from there