induwara.lk
induwara.lkDeveloper · AI

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.

By Induwara AshinsanaUpdated Jul 2, 2026
Repair broken JSON
ECMA-404 verified
70 bytes

Everything runs in your browser. Nothing is uploaded.

Try a sample
NDJSON

Fixes syntax only and leaves ambiguous content untouched, so the meaning of your data never changes.

Valid JSON
Input
70 B
Output
75 B
+5 B
4 fixes applied
  • Stripped Markdown ``` code fence
  • Converted 2 single/smart-quoted strings to double quotes
  • Replaced 1 non-JSON literal (True/False/None/NaN/Infinity/undefined)
  • Removed 1 trailing comma
Verified 2026-07-02

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.

  1. Unwrap Markdown fences. A leading ```json block (or plain ```) and its closing fence are stripped to leave the inner content.
  2. Strip comments. // line and /* block */ comments are removed — they are not part of ECMA-404 but models emit them.
  3. Normalise quotes.Single-quoted and curly “smart” quotes are converted to double quotes, escaping any embedded double quote (ECMA-404 requires double-quoted strings).
  4. Quote unquoted keys. Bare identifier keys such as { name: 1 } become { "name": 1 }.
  5. Fix non-JSON literals. Python True/False/None become true/false/null, and NaN, Infinity, undefined become null.
  6. Remove trailing commas. A comma before a closing ] or } is dropped.
  7. Escape control characters. Raw newlines and tabs inside a string become \n/\t; other control characters become \uXXXX (RFC 8259 §7).
  8. 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.
  9. 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

Classic ChatGPT reply (Standard mode)

Input

```json
{ "items": ['tea', 'rice',], "total": 1450, "paid": True }
```
  1. Strip the ```json code fence
  2. Convert 'tea' and 'rice' to "tea" and "rice"
  3. Remove the trailing comma after 'rice'
  4. Replace Python literal True with true
  5. JSON.parse the result → valid ✓

Output (minified)

{"items":["tea","rice"],"total":1450,"paid":true}

Truncated output — model hit the token limit (Standard mode)

Input

{"users": [{"id": 1, "name": "Nimal"}, {"id": 2, "name": "Kama
  1. Close the unterminated string "Kama → "Kama"
  2. Open structure is { [ { — close as } ] } in order
  3. "Kama" is flagged as recovered-from-truncation to double-check
  4. JSON.parse the result → valid ✓

Output (minified)

{"users":[{"id":1,"name":"Nimal"},{"id":2,"name":"Kama"}]}

Python dict with comments (Standard mode)

Input

{
  // primary key
  id: 42,
  name: 'Kamala Perera',
  roles: ["admin", "editor",],
}
  1. Remove the // line comment
  2. Quote the unquoted keys id, name and roles
  3. Convert 'Kamala Perera' to "Kamala Perera"
  4. Remove the trailing comma after "editor"
  5. JSON.parse the result → valid ✓

Output (minified)

{"id":42,"name":"Kamala Perera","roles":["admin","editor"]}

Frequently asked questions

Sources & references

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

Rate this tool
Be the first to rate

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.