Common JSON Syntax Errors and How to Fix Them
The mistakes that make JSON invalid, such as trailing commas, single quotes and unquoted keys, with a broken and a fixed example.
What valid JSON requires
JSON is stricter than JavaScript object syntax. Keys and strings must use double quotes, items are separated by commas with no comma after the last one, and the only values allowed are strings, numbers, true, false, null, objects and arrays.
The most common errors
Trailing comma: {"a": 1,} is invalid. Remove the comma after the last item.
Single quotes: {'a': 1} is invalid. Use double quotes: {"a": 1}.
Unquoted keys: {a: 1} is invalid. Write {"a": 1}.
Comments: JSON has no comment syntax, so // note and /* note */ must be removed.
Missing comma: two items next to each other, such as {"a": 1 "b": 2}, need a comma between them.
Unsupported values: undefined, NaN and Infinity are not valid JSON. Use null or a string instead.
Unescaped characters in strings: a double quote inside a string must be written as \", and a line break inside a string must be written as \n.
A broken example and its fix
Broken: {'name': 'Ada', age: 36, "tags": ["math",],}
Fixed: {"name": "Ada", "age": 36, "tags": ["math"]}
The broken version has four problems at once: single quotes, an unquoted key, and two trailing commas.
Finding the problem faster
Paste the text into the JSON Validator to see whether it parses, or into the JSON Formatter to pretty-print it. The wording of the error message comes from your browser, so it differs between Chrome, Firefox and Safari. It usually points to the position where parsing stopped, which is often just after the real mistake, so check the characters before it too.
Fix one error at a time and run it again: a parser stops at the first problem it finds.
If you copied JSON from a log or a web page, look for smart quotes (“ ”) that replaced straight quotes, and for text before or after the JSON object.
Try the tools
- JSON Formatter — Beautify and validate JSON with indentation.
- JSON Validator — Validate JSON syntax locally.
- JSON Minifier — Remove JSON whitespace for compact payloads.