Skip to content
DDevToolery

Why is my JSON invalid?

The handful of mistakes behind almost every parse error.

The validator reports the line and column where parsing failed. The actual mistake is usually just before that point.

Trailing commas

JavaScript allows a comma after the last element. JSON does not.

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

Single quotes

JSON strings must use double quotes, for both keys and values. Single quotes are a JavaScript object literal, not JSON.

Unquoted keys

Every key must be a quoted string. {name: "Ada"} is valid JavaScript and invalid JSON.

Comments

JSON has no comment syntax. Both // and /* */ are parse errors. Formats that allow them — JSON5, JSONC — are different formats.

Unescaped characters in strings

A literal newline, tab or double quote inside a string must be escaped as \n, \t or \". Use the JSON escape tool to do it correctly.

Special values

NaN, Infinity and undefined are not valid JSON. Neither is a leading zero or a trailing decimal point in a number.