Guides

Fix JSON Syntax Errors: 8 Common Causes

Last updated: 2026-11-05

What does “Unexpected token” mean in JSON? See 8 common syntax errors and their fixes, plus two problems that raise no error at all.

Find the error first

The position, line or column in an error message is where the parser stopped. Paste your JSON into the JSON Formatter to see the line and column marked for you, which is much easier than counting characters.

That position is where the parser noticed a problem, which isn’t always where the mistake is. A missing comma, for instance, is reported at the next key, so look just before the marked spot too.

8 common errors

These messages come from Node.js 22. Chrome’s are essentially the same, while other browsers word them differently for the same problems.

Invalid JSONErrorFix
{"age": 20,}Expected double-quoted property nameRemove the last comma
[1, 2, 3,]Unexpected token ']'Remove the last comma
{'name': 'Tom'}Expected property name or '}'Use double quotes for keys and strings
{name: "Tom"}Expected property name or '}'Put double quotes around the key
{ /* comment */ "a": 1 }Expected property name or '}'Delete the comment
{"a": undefined}Unexpected token 'u'Use null, or remove the key
{"a": 1 "b": 2}Expected ',' or '}' after property valueAdd a comma between the pairs
{"a": [1, 2}Expected ',' or ']' after array elementAdd the missing ]

Two close relatives: NaN isn’t a valid value either and gives Unexpected token 'N', and a real line break inside a string gives Bad control character in string literal, so write it as \n.

Why JSON is so strict

JSON looks like a JavaScript object, but it’s a separate data format with no comments, trailing commas or single quotes. Objects copied from JavaScript code often fail for exactly these reasons.

Some config files do allow comments. tsconfig.json, for example, uses JSONC. Those files need a matching parser, because plain JSON.parse will reject them.

No error, but the data changed: large integers

JSON itself doesn’t limit numbers, but JavaScript numbers can’t represent integers exactly beyond 2^53. Parsing doesn’t fail. The number just quietly changes:

JSON.parse('{"id": 9007199254740993}').id
// 9007199254740992

Order numbers and user IDs are the usual victims. The safe fix is to have the API send them as strings. The JSON Formatter shows a warning under the result when this happens.

No error, but data is missing: duplicate keys

JSON.parse('{"a": 1, "a": 2}')
// { a: 2 }

When a key appears twice at the same level, JavaScript keeps only the last value and gives no warning. Watch for this when merging config by hand.

A simple debugging order

  1. Paste the JSON into the formatter and note the marked line and column.
  2. Check the commas, quotes and brackets just before that position.
  3. Fix one problem and validate again, because later errors only show up once earlier ones are gone.
  4. Once it’s valid, check for long numbers and duplicate keys.