How to Fix Invalid JSON: Every Common Error, Decoded
JSON parse errors look cryptic but come from a tiny set of causes. This guide maps each error message to its actual meaning, shows the fix, and explains when one-click repair is safe.
In short
Fix invalid JSON by reading the parser's error position, then matching it to one of five recurring causes: trailing commas, single quotes, unquoted keys, comments, or JavaScript-only values like undefined and NaN. A validator with line-and-column reporting finds the exact spot, and mechanical mistakes can be auto-repaired; truncated or ambiguous structures still need a manual fix.
Reading the error message
Parsers stop at the first violation and report where they gave up — which is near, but not always exactly at, the real mistake. 'Unexpected token }' usually means the problem is just before the brace (a trailing comma, a missing value). 'Unexpected end of input' means the document stopped early — an unclosed brace or bracket, or a truncated copy-paste. 'Unexpected token ' (a quote) often signals single quotes used where doubles are required.
A validator with line-and-column reporting (and editor markers) collapses the search: paste, read the position, look one token left.
The five classics and their fixes
Trailing commas — [1, 2, 3,] → remove the final comma; JSON forbids it everywhere. Single quotes — 'name' → "name"; both keys and strings need double quotes. Unquoted keys — {name: 1} → {"name": 1}; that's JavaScript syntax, not JSON. Comments — delete them, or switch the file to JSON5 if comments are genuinely needed. JavaScript values — undefined, NaN, Infinity have no JSON form; use null or strings.
| Mistake | Example | Fix |
|---|---|---|
| Trailing comma | [1, 2, 3,] | Remove the final comma |
| Single quotes | 'name': 'Ada' | Use double quotes: "name": "Ada" |
| Unquoted keys | {name: 1} | Quote the key: {"name": 1} |
| Comments | // note or /* note */ | Delete them, or switch the file to JSON5 |
| JS-only values | undefined, NaN, Infinity | Replace with null or a string |
// ✗ All five mistakes in one (not valid JSON):
{
name: 'Ada', // unquoted key, single quotes, comment
"score": NaN, // NaN doesn't exist in JSON
"tags": ["a", "b",], // trailing comma
}
// ✓ Fixed:
{ "name": "Ada", "score": null, "tags": ["a", "b"] }Sneakier breakages
Some invalid JSON looks perfect. Smart quotes — a document that traveled through Word or a chat app may have “curly” quotes, which are not JSON string delimiters. Invisible characters — a BOM at the file start or a non-breaking space breaks parsers that show you nothing wrong. Truncation — logs and clipboards cut long payloads mid-string, producing 'unexpected end of input' on a document that looks complete because the end scrolled away. Double encoding — a JSON string of JSON (\" everywhere) isn't broken, it's wrapped: unescape it first.
When to auto-repair vs. fix by hand
Mechanical mistakes — quotes, commas, comments, unquoted keys, smart quotes — are exactly what automated repair handles: our JSON Repair (the wrench icon on the formatter) fixes all of them in one click and re-validates. Structural problems — truncated payloads, genuinely ambiguous nesting — need a human, because the repairer would have to guess your intent. The workflow that always works: Validate → read the position → repair or hand-fix → validate again.
Sources
Frequently asked questions
Why does my JSON work in the browser console but fail to parse?
Because the console evaluates JavaScript, which is more permissive: single quotes, unquoted keys, trailing commas and comments are all legal JS but illegal JSON. If it only works in a console, it's an object literal — not JSON.
Can automatic repair corrupt my data?
Repair only fixes mechanical syntax (quotes, commas, comments, bare keys) — values are never altered. The one risk is truncated input, where the repairer must guess where structures close; always review repaired output before using it in production.
How do I find one error in a 10,000-line document?
Don't scroll — validate. A parser reports the first violation's exact line and column; our validator additionally underlines it in the editor. Fix, re-validate, repeat: errors reveal themselves one at a time.
Paste your broken JSON into the JSON Validator — exact error positions, editor markers, and one-click repair.
Fix yours nowKeep working
Related tools
JSON Validator
Strict RFC 8259 validation with the exact line and column of every error — plus one-click repair for broken JSON.
JSON Formatter
Format, beautify, and validate JSON instantly in a professional VS Code-style editor — free, fast, and 100% private.
JSON Parser
Run a real JSON parse in your browser — see exactly what your application will see, or exactly where it will fail.
String to JSON
Paste an escaped JSON string — with all its backslashes — and get the real, formatted JSON back.
JSON Repair
Paste JSON that almost parses — single quotes, trailing commas, comments, a truncated tail — and get valid, formatted JSON back.
JSON Editor
A full VS Code-style editing experience for JSON — highlighting, error squiggles, undo/redo, search, and formatting in one place.