AI JSON Repair — Fix Broken JSON From ChatGPT & LLMs
Paste the malformed JSON a model returned — fences, trailing commas, single quotes, Python True/None, comments, or a truncated tail — and get valid, parseable JSON instantly. It lists every fix applied so you can trust the output. Runs entirely in your browser.
How it works
Large language models are trained on Markdown and on Python/JavaScript source, so the “JSON” they return is often not valid JSON at all. The repairer applies a fixed, ordered pipeline of pure string-to-string transforms and then validates the result with the browser's own JSON.parse. A fix is only recorded if it actually changed the text.
- Unwrap Markdown fences. A leading
```jsonblock (or plain```) and its closing fence are stripped to leave the inner content. - Strip comments.
// lineand/* block */comments are removed — they are not part of ECMA-404 but models emit them. - Normalise quotes.Single-quoted and curly “smart” quotes are converted to double quotes, escaping any embedded double quote (ECMA-404 requires double-quoted strings).
- Quote unquoted keys. Bare identifier keys such as
{ name: 1 }become{ "name": 1 }. - Fix non-JSON literals. Python
True/False/Nonebecometrue/false/null, andNaN,Infinity,undefinedbecomenull. - Remove trailing commas. A comma before a closing
]or}is dropped. - Escape control characters. Raw newlines and tabs inside a string become
\n/\t; other control characters become\uXXXX(RFC 8259 §7). - Complete truncated structure. If the model was cut off, the open string is closed, then every unbalanced
{and[is closed in stack order and any dangling comma removed. - Validate & format. The result is run through
JSON.parse. On success it is re-serialised in your chosen output style; on failure the parser's error and location are shown.
Because the final JSON.parse is the ground-truth oracle, the tool never claims “valid” for something that isn't. The two worked examples below are wired in as assertions and re-checked on every deploy — 2 of 2 pass right now.
Worked examples
Frequently asked questions
Sources & references
- ECMA-404, 2nd edition — The JSON Data Interchange Syntax (the grammar we repair to)
- IETF RFC 8259 — JSON Data Interchange Format (string & escape rules, §7)
- jsonrepair (josdejong, MIT) — the reference repair transformation set
The transformation set was last reconciled against these sources on 2026-07-02. Repairs are deterministic and run entirely in your browser; validity is confirmed by the native JSON.parse.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a case it can't repair, or want a fix added?
Email me at [email protected] — paste the input and I'll investigate.