Fix · JSON Repair

JSON Repair — Fix Broken JSON Online

Paste broken JSON and get it fixed automatically: trailing commas, single quotes, unquoted keys, Python constants, markdown fences, and truncated output. Deterministic fixes, right in your browser.

No sign-up to start · Runs in your browser

JSON Repair
Open repaired JSON in editor
Broken JSON
Repaired JSON

Runs entirely in your browser — nothing is uploaded.

{'user': 'Ada', role: 'admin', "tags": ["read", "write",], "active": True, "score": NaN
Paste broken JSON and click Repair: the tool strips markdown fences and leading prose, converts single quotes to double quotes, quotes bare keys, deletes trailing commas and comments, rewrites True/False/None/undefined/NaN/Infinity to valid JSON values, normalizes smart quotes, and closes truncated strings and brackets. Every fix is deterministic and appears in the status line, so you can audit what changed. Everything runs in your browser: no upload, no account. If the input still cannot parse, you get the real parse error instead of a guess.

Example: repairing a truncated AI answer

Broken input (AI answer, cut off mid-string)
Sure, here is the corrected config:

```json
{
  // retry settings
  model: 'gpt-4o',
  'max_tokens': 4096,
  "temperature": 0.7,
  "tags": ["prod", "v2",],
  "stream": True,
  "stop": None,
  "penalty": NaN,
  "note": "cut off mid-sent
Repaired output
{
  "model": "gpt-4o",
  "max_tokens": 4096,
  "temperature": 0.7,
  "tags": [
    "prod",
    "v2"
  ],
  "stream": true,
  "stop": null,
  "penalty": null,
  "note": "cut off mid-sent"
}

The status line for this run reads "Repaired — removed markdown code fences, removed comments, converted single quotes, quoted unquoted keys, fixed constants (True/None/NaN…), removed trailing commas, closed unclosed brackets". Two details deserve a second look: NaN became null because JSON has no NaN, and the "note" string got closed right where the output stopped. Repair restores structure; the bytes lost to truncation stay lost.

How to fix broken JSON

  1. 1

    Paste the broken JSON

    Drop in whatever you have: a ChatGPT or Claude answer still wrapped in ```json fences, a Python dict from print() or a log, a JavaScript object literal, or a response that stopped mid-string.

  2. 2

    Click Repair

    The engine runs its passes in a fixed order: fence and prose removal, smart-quote normalization, comment stripping, a string-aware token pass for quotes, keys, constants, and trailing commas, and finally bracket closing.

  3. 3

    Read the fix list

    The status line names each fix the engine applied, for example "converted single quotes, quoted unquoted keys". No fix happens silently, so you can audit the whole repair in seconds.

  4. 4

    Check values that changed meaning

    Most fixes are pure syntax, but NaN, Infinity, undefined, and None all become null. If downstream code treats those cases differently, adjust them before you pass the data on.

  5. 5

    Open the result in the editor

    One click carries the repaired JSON into the full editor, where you can format it, validate it, browse it as a tree or mind map, or run AI actions on it.

What it fixes

AI output artifacts

The engine removes ```json fences and the lead-in sentence before them, which on its own rescues most JSON copied from ChatGPT, Claude, or Gemini.

Python dict syntax

Single-quoted strings become double-quoted, and True, False, and None become true, false, and null, so printed dicts and repr() output parse as JSON.

JavaScript literals

The engine quotes bare keys, strips // and /* */ comments, drops trailing commas, and rewrites undefined, NaN, and Infinity to null.

Smart quotes

Curly quotes pasted from Word, Google Docs, or chat apps turn back into straight quotes ahead of the string-aware passes. This pass covers the whole text, so curly apostrophes inside values are straightened too.

Truncated documents

The repairer closes an unterminated final string, removes dangling commas or colons, and appends missing closing brackets in stack order, so output cut off at a token limit still parses.

Deterministic and reported

No AI and no randomness: the same input always produces the same output, and every applied fix appears in the status line. Input that still cannot parse throws the remaining error.

What breaks JSON in practice

LLM output is the top source of broken JSON today. Models wrap answers in ```json fences, put a sentence of prose before the payload, and stop mid-token at an output limit. The object inside is often fine; the wrapper and the missing tail are what make JSON.parse throw "Unexpected token" at position 0 or "Unterminated string" at the end.

Python is the second source. print(payload) and logging a dict both emit repr() syntax: single quotes plus True, False, and None with capital letters. json.dumps() would have produced valid JSON, but once the text sits in a log file that option is gone.

JavaScript object literals fail for a different reason. Source code and console output allow bare keys, // comments, trailing commas, undefined, NaN, and Infinity. All of that is valid JavaScript and none of it is valid JSON, which surprises you the first time you paste a config object into a parser.

The rest is transport damage: word processors swap straight quotes for curly ones, a payload gets copied together with the sentence introducing it, or log rotation cuts a line in half. Each of these breaks in a predictable way, which is why a deterministic repairer can fix them.

The fixes, in the order they run

The repairer first tries a plain JSON.parse; input that already parses comes back pretty-printed and otherwise untouched. Otherwise it strips markdown fences, drops any prose before the first { or [, and normalizes smart quotes. Those three passes alone rescue most AI answers.

Comment stripping and the token pass are string-aware: content inside double-quoted strings passes through untouched, so a URL containing // or a string containing the word True never gets rewritten. The one exception is smart-quote normalization, which runs on the whole text because string boundaries in broken input are not yet trustworthy; a curly apostrophe inside a value comes out straight. The engine re-emits single-quoted strings through JSON.stringify, which escapes embedded quotes and backslashes correctly.

The token pass quotes bare keys, lowercases True and False, and rewrites None, undefined, NaN, and Infinity to null, because JSON defines no representation for them. It also deletes a comma whenever the next token closes an object or array.

Truncation repair runs last: close an unterminated final string, strip a dangling comma or colon, and append closing braces and brackets in stack order. A strict JSON.parse then decides the outcome. Success means pretty-printed output plus the full fix list; failure means you see the remaining parse error.

Repair, validate, or AI Fix?

The JSON validator is read-only: it points at the first offending line and column and leaves your input alone. Reach for it when you control the producer, because fixing the code that emits broken JSON beats repairing its output forever.

Repair is for the consumer side, when the broken JSON comes from a system you cannot change: a third-party API, an old log, a model response. It rewrites the known mechanical breakages, tells you which ones it found, and behaves identically on every run, so you can build a habit around it.

AI Fix, an action inside the editor, handles what no mechanical pass can: keys named inconsistently, values in the wrong shape, a structure that needs reorganizing. It uses credits (signup includes 1,000 free) and, unlike this page, it sends the document to a model. Pick it when the problem is semantic rather than syntactic.

Limits: what repair will not do

Repair does not invent data. If the input is not roughly JSON-shaped, say a YAML file or a paragraph of prose, the tool throws the remaining parse error instead of producing plausible-looking output. A repairer that always returns something would be worse than one that sometimes refuses.

Some fixes lose information by necessity. NaN, Infinity, undefined, and None flatten to null, comments disappear, and prose outside the payload gets discarded. The fix list exists so you can review each of these decisions; read it before the output goes anywhere important.

Truncation repair restores parseability, not content. The final string may end mid-word, and an array may hold fewer items than the producer intended, with no marker of where the cut happened. When the payload carries counts or checksums, verify them after repair rather than trusting the closed brackets.

Frequently asked questions

Is the JSON repair tool free?

Yes. It runs in your browser with no account and no upload; the JSON never leaves the page.

Can it fix JSON copied from ChatGPT or Claude?

That is its main job. It strips the ```json fences and the lead-in sentence, closes output that stopped at a token limit, and fixes the single quotes and bare keys models sometimes emit. If the answer contains no JSON at all, there is nothing to recover.

Does the repair use AI?

No. Each fix is a deterministic text transformation, so the same input always yields the same output. The editor offers a separate AI Fix action for semantic problems that a mechanical pass cannot solve.

Can it convert a Python dict to JSON?

Yes, for literal values: single quotes become double quotes, True/False/None become true/false/null, and trailing commas disappear. Non-literal reprs such as datetime(2024, 1, 1) are not JSON-shaped and still fail with a parse error.

What happens with truncated JSON?

The repairer closes the unterminated string, removes a dangling comma or colon, and appends the missing closing brackets in the right order. The document parses again, but the bytes lost to truncation are gone; expect the last value to be a visibly cut-off string.

Does it ever change my data values?

Mostly no: the comment and token passes copy text inside double-quoted strings untouched. Two exceptions exist. NaN, Infinity, undefined, and None become null because JSON lacks them, and smart-quote normalization straightens curly quotes everywhere, including inside string values. Both rewrites appear in the fix list.

What if the input still cannot be repaired?

The tool throws the remaining parse error rather than guessing. YAML, XML, CSV, and plain prose are out of scope; for structural rewrites such as renaming keys or reshaping objects, use AI Fix in the editor.

Should I use JSON repair or the JSON validator?

Use the validator when you want a diagnosis, for example to fix the code that produced the JSON. Use repair when you need the data to parse right now. Running repair and reading its fix list often diagnoses the problem faster than either alone.

Related tools

Fix your JSON now

Open the Editor