You've written JSON that looks perfectly fine. Braces match, keys are quoted, commas are in place. Yet JSON.parse() throws Unexpected token at a position that makes no sense.
Sound familiar? Here are six invisible traps that break perfectly "correct-looking" JSON — and how to spot each one.
1. Trailing commas
{"a": 1, "b": 2,} — the comma after the last item is invalid in strict JSON (it's legal in JavaScript objects, which is why it sneaks in). Editors rarely flag it. Drop the final comma and it parses.
2. Smart (curly) quotes
Copy JSON out of a word processor, email client, or chat app and the quotes come back curly: " and " instead of ". JSON only accepts the straight double quote (U+0022). Curly quotes are the #1 cause of "my JSON works in my head but not in code".
3. The hidden BOM
Files saved as UTF-8 with BOM start with an invisible byte sequence before the first {. JSON.parse() sees it as an unexpected token — the classic "error at line 1, column 1" mystery. Save as UTF-8 without BOM and it disappears.
4. Non-breaking spaces
A space that isn't a space. NBSP (U+00A0) copied from formatted text looks like whitespace to your eyes but is invalid JSON syntax when it hides between keys and colons.
5. Single quotes and unquoted keys
{'a': 1} and {a: 1} are valid JavaScript — but not JSON. RFC 8259 requires double-quoted keys and values. Hand-written config files drift into JS-object syntax all the time.
6. Duplicate keys don't throw — they silently overwrite
{"id": 1, "id": 2} parses fine, but the first value is silently discarded. Different parsers disagree on which value wins, so this causes subtle, hard-to-debug data loss.
How to debug these fast
Don't eyeball it — get a precise error location. Paste the payload into a formatter that reports the exact line and column of the first syntax error (a BOM shows up as an error at position 0, a dead giveaway). A collapsible tree view also makes duplicate keys easy to spot after a successful parse.
I use the free JSON Formatter on CodeToolbox for this — it's 100% client-side (your data never leaves the browser), reports exact error positions, and switches between format / minify / validate modes. No signup, no uploads.
The 30-second fix checklist
- Replace curly quotes with straight quotes
- Drop trailing commas
- Save without BOM
- Double-quote every key
Nine times out of ten it's one of these. Happy parsing!