JSON was designed to be boring: a small set of rules, no comments, no functions, nothing clever. The upside is that it is unambiguous. The downside is that it looks enough like JavaScript to invite every habit JavaScript allows, and then rejects them all.

Six mistakes account for almost every parse error.

Mistake Invalid Valid
Trailing comma {"a":1,} {"a":1}
Single quotes {'a':1} {"a":1}
Unquoted key {a:1} {"a":1}
Comment {"a":1 // note} {"a":1}
undefined or NaN {"a":undefined} {"a":null}
Smart quotes {“a”:1} {"a":1}

1. The trailing comma

JavaScript tolerates [1,2,3,]. JSON does not. It is the most common error by a wide margin, and it usually appears after someone deletes the last item of a list and leaves the comma behind.

2. Single quotes

JSON strings use double quotes, always. Single quotes are valid in JavaScript and in Python, which is exactly why they end up in JSON copied from either.

3. Unquoted keys

{name: "Ada"} is JavaScript. JSON requires {"name": "Ada"}. Same for the value side: only strings, numbers, booleans, null, arrays and objects are allowed — no functions, no dates, no regex.

4. Comments

There is no comment syntax in JSON. Not //, not /* */, not #. If you need notes in a config file, use JSON5, YAML or TOML — or put the explanation in a "_comment" key and accept that it is data.

5. undefined and NaN

Neither exists in JSON. undefined becomes null (or the key disappears), and NaN becomes null too, which is its own small tragedy because it silently changes the meaning. Large numbers have a similar problem: JSON numbers are IEEE 754 doubles, so any integer above 9,007,199,254,740,991 loses precision. Database IDs are the usual victim.

6. Smart quotes

Copy a snippet from Word, Google Docs or a PDF and the quotes may arrive as “ ” instead of " ". They look identical in most fonts and are a different character. The same happens with the non-breaking space (U+00A0) that word processors insert, which produces an error message pointing at a space that looks perfectly normal.

If the parser says the error is at position 42 and position 42 looks fine, it is almost certainly an invisible character. Paste the text into the JSON formatter and it will point at the line and character.

Reading the error message

Most parsers report a character offset, and they disagree on whether it is zero-based or one-based. Rather than counting, paste the document into a formatter: it parses the same way, shows the line and column, and pretty-prints once it succeeds.

If the JSON came from a spreadsheet, the CSV to JSON converter handles the quoting rules for you, which is usually faster than fixing them by hand.

JSON is strict on purpose. The strictness is why two systems written by strangers can exchange data without a meeting.

Hero photo: Coding Programming, CC0, via Openverse (StockSnap).