Five Reasons JSON.parse Fails (and Where They Come From)
Trailing commas, single quotes, comments, unquoted keys and NaN, with the exact error for each.
By the TurantTools Dev team · Updated October 27, 2026 · 3 min read
JSON is stricter than JavaScript. Five habits from JS code cause most "Unexpected token" errors. Here's what our formatter reports for each.
| Problem | Input | Error |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Trailing comma: remove the comma before }. (line 1, column 16) |
| Single quotes | {'a': 1} | Keys must use double quotes ("), not single quotes ('). (line 1, column 2) |
| Comment | {"a": 1 // note⏎} | Expected , or } after a value, found "/". Is a comma missing? (line 1, column 9) |
| Unquoted key | {a: 1} | Keys must be in double quotes. Found "a". (line 1, column 2) |
| NaN value | {"a": NaN} | Unexpected word starting with "N". Text values need double quotes; only true, false and null are allowed without them. (line 1, column 7) |
Where they come from
- Config files like
tsconfig.jsonand VS Code settings accept comments and trailing commas (JSONC), so habits leak into real JSON. - Copying a JavaScript object from the console gives single quotes and unquoted keys.
- Serialising
NaNorInfinityneeds a decision:JSON.stringifyturns them intonull.