Skip to main content

← Back to blog

Common JSON Errors and How to Fix Them

Almost every “Unexpected token in JSON” error comes from the same short list of mistakes. Here they are, with the fix for each. (New to the format? Start with What is JSON.)

1. Trailing commas

JSON does not allow a comma after the last item:

{ "a": 1, "b": 2, }   ← invalid
{ "a": 1, "b": 2 }    ← valid

2. Single quotes

Strings and keys must use double quotes:

{ 'name': 'Ann' }   ← invalid
{ "name": "Ann" }   ← valid

3. Unquoted keys

Unlike JavaScript objects, JSON keys must be quoted:

{ name: "Ann" }     ← invalid
{ "name": "Ann" }   ← valid

4. Comments

JSON has no comments. Remove // and /* */ before parsing.

5. Wrong or missing brackets

Every { needs a } and every [ a ]. A common one is mixing them up or forgetting to wrap multiple records in an array [ … ].

6. Not-a-number values

NaN, Infinity and undefined aren’t valid JSON. Use a number, a string, or null.

The fastest fix: validate

Rather than hunt by eye, paste your JSON into a validator that points to the exact error location:

Fix the six mistakes above and the vast majority of “invalid JSON” problems disappear — everything runs locally in your browser, so even sensitive payloads stay private.