Skip to main content

extract_json

Function extract_json 

Source
pub fn extract_json(raw: &str) -> Result<NormalizedOutput, NormalizationError>
Expand description

Extract a JSON body from a raw LLM response.

Tries extraction strategies in order of specificity:

  1. Fenced JSON (\``json`)
  2. Generic fence (\```) whose content parses as JSON
  3. Direct JSON (trimmed input starts with { or [)
  4. Embedded JSON (first { to last balanced })

Returns the extracted body and the method used, or an error if no JSON could be found.