Repair broken JSON (LLM output) and list the fixes
repair_jsonTurn broken or messy JSON text into valid JSON. Strips Markdown code fences and prose before/after the JSON, removes comments and trailing commas, converts single/curly quotes, quotes unquoted keys, maps Python None/True/False, inserts missing commas, closes truncated strings/arrays/objects, and wraps NDJSON / several concatenated objects into one array. Returns the parsed value (json), the repaired text, and the list of fixes applied; valid input passes through unchanged with no fixes. Optional schema (+ coerce) also validates the result. Fails with isError (code unrepairable / no_json_found) when nothing JSON-like can be recovered. Pure computation: read-only, no network access, inputs not stored. Same engine and limits as POST /api/v1/repair.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| draft | No | JSON Schema draft. Default: from the schema's $schema, else 2020-12. | |
| input | Yes | The raw (possibly broken) JSON text, e.g. an LLM reply with code fences and prose around the JSON. Max 102,400 bytes (UTF-8). | |
| coerce | No | Convert values toward the schema's declared types before validating: "42" → 42, "true" → true, "null" → null, 5 → "5", x → [x]. Each change is listed in coercions. | |
| format | No | Layout of the returned text: compact (default), pretty (2-space indent), or preserve (jsonrepair's output, keeps original spacing and long-number digits). | compact |
| schema | No | A JSON Schema (draft 2020-12 by default; 2019-09, 7 and 4 also supported). Only local $refs (#/...) resolve; remote $refs are an error. Max 32 KB. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | ||
| json | Yes | The repaired JSON value (coerced if coerce was used) | |
| plan | No | ||
| fixes | Yes | ||
| format | No | ||
| schema | No | ||
| values | No | Number of top-level JSON values found (more than 1 = wrapped in an array) | |
| changed | Yes | false when the input was already valid JSON | |
| version | No | ||
| warnings | No | ||
| inputBytes | No | ||
| outputBytes | No | ||
| inputWasValid | Yes |