Wrapper for the JsonishParser Java class.
Provides SAP (Schemaless Adaptive Parsing) for malformed JSON from LLMs. Handles unquoted keys/values, trailing commas, markdown code blocks, etc.
Wrapper for the JsonishParser Java class. Provides SAP (Schemaless Adaptive Parsing) for malformed JSON from LLMs. Handles unquoted keys/values, trailing commas, markdown code blocks, etc.
(parse-json input)Parses JSON-ish string using full SAP (Schemaless Adaptive Parsing) cascade.
Handles malformed JSON from LLMs using a multi-stage parsing strategy:
Returns the best candidate (highest score) with applied fixes as warnings.
Params:
input - String. JSON-ish input to parse. Must not be nil or empty.
Returns: Map with:
Examples: (parse-json "{"a": 1}") => {:value {:a 1}, :warnings []}
(parse-json "{a: 1, b: 2,}") => {:value {:a 1, :b 2}, :warnings ["Unquoted key: a" "Trailing comma"]}
(parse-json "json\n{\"x\":42}\n")
=> {:value {:x 42}, :warnings ["ExtractedFromMarkdown:json"]}
Throws: IllegalArgumentException if input is nil or empty.
Parses JSON-ish string using full SAP (Schemaless Adaptive Parsing) cascade.
Handles malformed JSON from LLMs using a multi-stage parsing strategy:
1. Strict JSON - Valid JSON without any fixes (score: 100)
2. Markdown extraction - JSON from code blocks (score: 90)
3. Multi-object extraction - All balanced {}/[] in text (score: 70-80)
4. Fixing parser - Malformed JSON with repairs (score: 10-50)
5. String fallback - Raw input as string (score: 0)
Returns the best candidate (highest score) with applied fixes as warnings.
Params:
`input` - String. JSON-ish input to parse. Must not be nil or empty.
Returns:
Map with:
- :value - Parsed Clojure data structure
- :warnings - Vector of fix descriptions applied during parsing
Examples:
(parse-json "{\"a\": 1}")
=> {:value {:a 1}, :warnings []}
(parse-json "{a: 1, b: 2,}")
=> {:value {:a 1, :b 2}, :warnings ["Unquoted key: a" "Trailing comma"]}
(parse-json "```json\n{\"x\":42}\n```")
=> {:value {:x 42}, :warnings ["ExtractedFromMarkdown:json"]}
Throws:
IllegalArgumentException if input is nil or empty.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |