10 Common JSON Syntax Errors and How to Fix Them
The most frequent reasons JSON fails to parse, with broken and fixed examples for each: trailing commas, single quotes, comments, unescaped characters, and more.
- json
- errors
- debugging
- validator
Why JSON errors are so common
JSON is strict. Unlike JavaScript object literals, it allows no shortcuts, so small habits from other languages break parsing. Below are the ten mistakes we see most, each with a fix.
1. Trailing comma
{
"a": 1,
"b": 2,
}Remove the comma after the last item:
{
"a": 1,
"b": 2
}2. Single quotes
{ 'name': 'Ada' }JSON requires double quotes:
{ "name": "Ada" }3. Unquoted keys
{ name: "Ada" }Wrap the key in double quotes: { "name": "Ada" }.
4. Comments
{
// user name
"name": "Ada"
}JSON has no comments. Remove them, or move the note into a field such as "_comment". If you need comments in config files, consider JSONC or JSON5, but parse them with a tool that supports those formats.
5. Missing comma between items
{
"a": 1
"b": 2
}Add the comma after 1.
6. Unescaped quotes inside strings
{ "quote": "She said "hi"" }Escape inner quotes with a backslash:
{ "quote": "She said \"hi\"" }7. Raw newlines or tabs inside strings
A literal line break inside a string is invalid. Use the escape sequence \n (or \t for tabs) instead.
8. Invalid values: undefined, NaN, Infinity
These JavaScript values do not exist in JSON. Use null, or a string or number that your application understands.
9. Mismatched brackets
{ "items": [1, 2, 3 }Every [ needs a ] and every opening brace needs a closing one. An editor with bracket matching, like the one in NiceJSON, highlights the partner so you can spot the gap.
10. Leading zeros and bad numbers
{ "zip": 01234, "price": .5 }JSON numbers cannot have leading zeros or start with a decimal point. Use "zip": "01234" (as a string) and "price": 0.5.
Reading the error message
| Message | Usual cause |
|---|---|
Unexpected token } | Trailing comma or missing value |
Unexpected token ' | Single quotes |
| Unexpected end of JSON input | Missing closing bracket or truncated data |
| Expected property name | Unquoted key or trailing comma |
| Bad control character in string | Raw newline inside a string |
Fastest way to find the problem
Paste the text into the NiceJSON validator. It reports the line and column of the first error, so you can fix issues one at a time instead of guessing.