JSON Common Syntax Errors
JSON is strict. A single misplaced character makes the whole document invalid, and the parser refuses to read any of it. The good news: almost every error comes from a short list of usual suspects. Each example below is broken on purpose — run it, read the message, then fix it.
Note: The messages shown come from V8 (Chrome, Edge, Node.js). Firefox and Safari use different wording, but the positions point at the same problem.
1. Trailing commas
The most common mistake, especially after deleting the last item of a list:
{
"colors": ["red", "green", "blue",]
}Invalid JSON: Unexpected token ']', ..."", "blue",]
}" is not valid JSON
Fix: remove the comma after "blue".
2. Single quotes
JSON strings and keys need double quotes:
{'name': 'Phuong'}Invalid JSON: Expected property name or '}' in JSON at position 1 (line 1 column 2)
3. Unquoted keys
Fine in JavaScript, invalid in JSON:
{name: "Phuong"}Invalid JSON: Expected property name or '}' in JSON at position 1 (line 1 column 2)
4. Comments
JSON has no comment syntax at all:
{
"port": 8080 // the default port
}Invalid JSON: Expected ',' or '}' after property value in JSON at position 17 (line 2 column 16)
Fix: delete the comment, or move the note into a key such as "_comment". If you really need comments in a config file, use JSONC or JSON5 (covered later).
5. Missing commas
Forgetting the comma between two pairs:
{
"width": 800
"height": 600
}Invalid JSON: Expected ',' or '}' after property value in JSON at position 19 (line 3 column 3)
The position points at the start of "height" — the parser expected a , or } there.
6. Invalid values
undefined, NaN, True or unquoted words are not JSON values:
{"score": NaN}Invalid JSON: Unexpected token 'N', "{"score": NaN}" is not valid JSON
{"active": True}Invalid JSON: Unexpected token 'T', "{"active": True}" is not valid JSON
7. Bad numbers
Leading zeros, a lone decimal point, or a plus sign are rejected:
{"zip": 01234}Invalid JSON: Unexpected number in JSON at position 9 (line 1 column 10)
Fix: codes with leading zeros (ZIP codes, phone numbers) should be strings: "zip": "01234".
8. Unescaped characters in strings
A real line break or tab inside a string is not allowed, and neither is an unescaped ":
{"quote": "He said "hello""}Invalid JSON: Expected ',' or '}' after property value in JSON at position 20 (line 1 column 21)
Fix: "He said \"hello\"".
9. Mismatched or missing brackets
{"items": [1, 2, 3}Invalid JSON: Expected ',' or ']' after array element in JSON at position 18 (line 1 column 19)
10. More than one top-level value
A JSON document holds exactly one value. Two objects next to each other are invalid (that is what JSON Lines is for):
{"id": 1}
{"id": 2}Invalid JSON: Unexpected non-whitespace character after JSON at position 10 (line 2 column 1)
Reading the error position
V8 messages often include position N (line L column C). Positions count characters from 0; lines and columns count from 1. In JavaScript you can use the position to show the broken spot:
const text = '{"a": 1, "b": 2,}';
try {
JSON.parse(text);
} catch (err) {
console.log(err.message);
const pos = Number(/position (\d+)/.exec(err.message)?.[1]);
console.log(text);
console.log(" ".repeat(pos) + "^");
}Expected double-quoted property name in JSON at position 16 (line 1 column 17)
{"a": 1, "b": 2,}
^
Checklist
| Symptom | Look for |
|---|---|
Expected double-quoted property name |
trailing comma, unquoted or single-quoted key |
Expected ',' or '}' after property value |
missing comma, comment |
Unexpected token |
undefined, NaN, True, .5, trailing comma in an array |
Expected ',' or ']' after array element |
missing comma or wrong closing bracket in an array |
Bad control character in string literal |
raw tab or line break inside a string |
Unexpected end of JSON input |
empty input, or text that stops right after :, , or [ |
Unterminated string |
a string with no closing " |
Unexpected non-whitespace character after JSON |
two values, extra bracket at the end |
Tip: Editors like VS Code underline JSON errors as you type. Turn on "format on save" and most of these mistakes become impossible to miss.
Test yourself
What is wrong with {"a": 1, "b": 2,}?
- Keys must not be quoted
- It has a trailing comma
- Numbers must be quoted
- Nothing
How should a ZIP code like 01234 be stored in JSON?
- 01234
- 1234
- "01234"
- 0x1234
Which error do you get for {"a":1}{"b":2}?
- Unexpected end of JSON input
- Unexpected non-whitespace character after JSON
- Bad control character
- No error