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

What this tool repairs

SymptomBeforeAfter
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 wrapperSure! {"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?
Trailing commas, unquoted or single-quoted keys and values, // and /* */ comments, JavaScript literals such as undefined, NaN and Infinity, Python True/False/None, smart quotes from word processors, Markdown code fences and surrounding prose, missing commas between values, strings that are missing their closing quote, and documents truncated by a token limit that are missing their closing braces or brackets.
Does it guarantee the repaired output is valid JSON?
The repaired text is parsed with JSON.parse before it is shown. If that parse fails, the tool tells you it could not repair the input rather than presenting something invalid. Some inputs are genuinely ambiguous — two missing quotes and a missing comma can be read several ways — and guessing silently would be worse than saying so.
Is my JSON uploaded anywhere?
No. The repair runs as JavaScript in this page. There is no server call, no upload of your text, and nothing is stored beyond your own clipboard when you press Copy.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close