TechCompare LogoTechCompare

Why does my JSON fail to parse? Common syntax errors and how to fix them fast

Use a JSON formatter to catch syntax errors instantly. The tool highlights the exact position of the error and shows you what the parser expected vs what it found. For VS Code users, the built-in JSON language mode catches most errors with red squigglies before you even try to parse.

JSON parse errors are frustrating because the error messages are usually unhelpful ("Unexpected token at position 847"). The three most common mistakes are trailing commas after the last item in an array or object, using single quotes instead of double quotes for strings, and using unquoted property keys.

By TechCompare · Updated

Topic
JSON parse errors
json-errors
Category
Troubleshooting
JSON knowledge base

How this is calculated

Trailing commas are the number-one culprit. JavaScript allows them, JSON does not. Developers who write JSON by hand in a JS/TS codebase naturally add trailing commas, then wonder why JSON.parse throws. Single quotes are a close second: JSON spec requires double quotes for all strings and keys, but JavaScript and Python both accept single-quoted strings, so the habit leaks. Unquoted keys (e.g., {name: "Alice"} instead of {"name": "Alice"}) work fine in JavaScript object literals but fail in strict JSON.

Verdict

The big three are concrete and fixable: trailing commas after the last array or object item (legal in JS, illegal in JSON), single quotes instead of double quotes on strings or keys (legal in JS and Python, illegal in JSON), and unquoted property keys (legal in JS object literals, illegal in strict JSON). A formatter catches all three at the exact character position the parser choked on, where the raw JSON.parse error typically reports only an opaque 'Unexpected token at position 847' that doesn't tell you which of the three you hit. VS Code's built-in JSON language mode adds the red-squiggly pass earlier, before you ever invoke parse, which is the cheaper way to catch the same mistakes. The human-only failure mode is hand-writing JSON in a JS/TS codebase and inheriting the trailing-comma habit, which a formatter surfaces the moment you paste the file in.

More JSON scenarios

Frequently asked questions

Why does JSON not allow trailing commas?
Douglas Crockford, JSON's creator, intentionally kept the spec minimal and strict. Trailing commas cause ambiguity in some parsers and were omitted to keep JSON a true subset of JavaScript's object literal syntax at the time.
What's the most common JSON parse error?
Trailing commas. JSON spec disallows commas after the last item in arrays or objects, but JavaScript and Python both accept them. The habit leaks, parsers throw, and the error position points at the character after the last comma. Most JSON formatters and linters flag this with red squiggles before you ever try to parse.
Why are single quotes invalid in JSON?
The JSON spec requires double quotes (`"`) for all strings and object keys. Single quotes aren't valid. JavaScript object literals allow single quotes, which is why the habit leaks. JSON.stringify in JS always emits double quotes. JSON parsers always require them. JSON5 and similar extensions relax this, but standard JSON strictly disallows single quotes.