JSON Repair — Fix Invalid JSON
Repair broken JSON in your browser: trailing commas, unquoted keys, single quotes, comments, truncation and missing braces. See every fix applied.
Broken JSON input
How it works
- Paste the broken JSON and click Repair JSON.
- The scanner rewrites each token it finds into strictly valid JSON and lists what it changed.
- The repaired text is parsed with
JSON.parsebefore it is shown — if that fails you get an error instead of invalid output. - Nothing leaves your browser. There is no request, no upload, and no storage of your input.
What this tool repairs
| Symptom | Before | After |
|---|---|---|
| Trailing comma | {"a":1,} | {"a":1} |
| Unquoted key | {name: "Ada"} | {"name":"Ada"} |
| Single quotes | {'a': 'b'} | {"a":"b"} |
| Comments | {"a":1 // hi } | {"a":1} |
| Smart quotes | {"a": “x”} | {"a":"x"} |
| Truncated output | {"a":[1,2 | {"a":[1,2]} |
| JS literal | {"a": undefined} | {"a":null} |
| Prose wrapper | Sure! {"a":1} hope that helps | {"a":1} |
| Missing value | {"a": } | {"a":null} |
About repairing JSON
Model outputs, hand-edited config files and copy-pasted payloads fail JSON parsing for a small set of predictable reasons. A trailing comma that JavaScript tolerates, a single quote that Python tolerates, an unterminated string left behind when a response hit its token limit — none of these are hard to fix by hand, but doing it by hand on a 500-line payload is exactly the kind of work that deserves automation.
The important property of a repair tool is not how many cases it handles, but whether it tells you what it did. A silent rewrite that turns undefined into null inside a field your code treats as "not provided yet" changes behaviour, and you would not notice until it mattered. Every repair here is listed, and every conversion to null is called out explicitly.
How the repair is made
The input is not patched with regular expressions. It is walked one character at a time by a scanner that tracks whether it is inside a string, which containers are open, and whether an object currently expects a key or a value. Each token is rewritten into strictly valid JSON as it is read, and every rewrite records a line in the "What was repaired" list, so you can audit what changed instead of trusting a black box.
Because the result is re-emitted and then parsed with <code>JSON.parse</code>, you either get valid JSON or an explicit failure message. Nothing in between. That guarantee is the reason the tool refuses some inputs rather than inventing data.
The judgement calls, and where they can be wrong
A quote inside a string closes that string only when what follows looks structural — a comma, a colon, a closing brace, or something shaped like the next object key. Without that rule <code>{"a": "x, "b": 2}</code> would run two values together; with it, an unescaped quote that really was meant as content gets escaped instead. Similarly, a newline inside a string is treated as content only when the following line does not look like it starts a new key — otherwise the string is closed at the break.
A token limit is not the only thing that truncates a document, and the harder ambiguity is structural. When an object was expecting a key and the token found there is not followed by a colon, the scanner drops the token and says so, because keeping it would require guessing whether it was a key without a value or a value without a key. Truncated documents hit this often: <code>{"id":2,"na</code> becomes <code>{"id":2}</code> with the fragment discarded, never <code>{"id":2,"na":""}</code>.
What it deliberately does not do
It does not guess missing data. A key with no value after the colon becomes <code>null</code> and the fix list says precisely that; it never invents an empty string or a zero. It does not reorder anything, does not deduplicate keys, and does not attempt to recover a schema — a key absent from your document stays absent.
Since everything runs on your machine, very large documents take as long as your browser takes. The tool has no size limit imposed by a server because there is no server in the path, but a paste of several megabytes will block the page for as long as the scan takes. <code>undefined</code>, <code>NaN</code> and <code>Infinity</code> have no <a href="/tools/json-formatter/">JSON</a> equivalent and are mapped to <code>null</code> — check those conversions against what your application expects, because losing the distinction between "absent" and "not a number" is a real change to the meaning of a payload.
Frequently Asked Questions
What kinds of broken JSON can this repair?
Does it guarantee the repaired output is valid JSON?
Is my JSON uploaded anywhere?
Is my data sent to a server?
Do I need an account or API key?
Can I use these tools offline?
All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.