Five JSON mistakes that break a parser
JSON looks forgiving because it resembles JavaScript, but the grammar is strict. Most parse errors come from five habits picked up in other formats. Once you know the shapes, a validator pinpoints them in seconds.
1. Trailing commas
JavaScript allows {"a": 1, "b": 2,}. JSON does not. The parser reaches the closing brace expecting another key and reports an unexpected token — usually at the position of the brace, not the comma, which is why the error message feels confusing.
How to spot it
Look at the line just above the reported position. A comma directly before a closing } or ] is the culprit.
2. Single quotes and unquoted keys
JSON strings use double quotes only, and every key must be a string. {name: 'ChatBen'} fails twice: the key is unquoted and the value uses single quotes. This style is valid in JavaScript object literals and in many configuration languages, which is exactly why it slips through.
3. Comments
There is no // or /* */ in JSON. If you need annotations next to configuration, either strip them before parsing or use a format that supports them. Some tools accept comments and then fail in a strict environment, which is worse than failing early.
4. A byte-order mark or smart quotes
A file saved by a Windows editor may begin with an invisible byte-order mark. Parsers reject it with "unexpected token" at position 0, which looks like a bug in the parser. Copying text out of a word processor causes a similar problem: curly quotes and non-breaking spaces are not ASCII quotes and spaces.
How to spot it
If the error is at position 0 and the file looks clean, re-save it as UTF-8 without BOM, or paste the text through a plain text editor.
5. Duplicate keys
The specification does not define which value wins when a key appears twice. Most parsers keep the last one and say nothing, so the bug surfaces later as a configuration value that "does not apply". A validator that reports duplicate keys catches this at editing time.
A fast way to find all five
Paste the payload into the JSON formatter. It reports the position of the first error and, once the document parses, re-indents it so nested structure is visible. A formatted document makes trailing commas and duplicate keys obvious at a glance.
- Valid input comes back indented and ready to read.
- Invalid input reports a line and column instead of a bare "unexpected token".
- Everything runs locally, so tokens and endpoints in your payload stay on your machine.