Common JSON syntax errors and how to fix them

JSON is stricter than JavaScript object literals. Most “Unexpected token” errors are a trailing comma, a single quote, or a bare key.

Trailing commas

// invalid
{ "a": 1, }

// valid
{ "a": 1 }

Keys and strings need double quotes

// invalid
{ a: 'hello' }

// valid
{ "a": "hello" }

No comments, no undefined

JSON has no // comments and no undefined. Use a separate format (JSONC) only if your consumer documents it. null is fine; bare NaN and Infinity are not.

Reading the error position

Validators that show line and column point at the first character the parser could not accept. Often the real mistake is a missing comma on the previous line.

The ToolDeck JSON formatter reports line and column and never uploads the document.

Questions

Is JSON5 the same as JSON?
No. JSON5 allows comments and unquoted keys. Standard JSON.parse rejects them.
Why does my API reject pretty-printed JSON?
Usually it is not the whitespace. Check Content-Type, trailing commas introduced by a hand edit, or a BOM at the start of the file.

Related tool: JSON formatter and validator. Runs in your browser; input is not uploaded.