Common JSON Errors and How to Fix Them
JSON is ubiquitous in web development, but even experienced developers occasionally encounter syntax errors that break their code. This guide walks you through the 8 most common JSON mistakes, shows you exactly what goes wrong, and provides instant fixes you can apply to your own data.
Whether you're building APIs, configuring services, or parsing data from external sources, understanding these errors will save you hours of debugging. Each error includes both the problematic code and the correct solution.
Need to validate JSON quickly?
Use SnapUtils' free JSON Formatter & Validator to instantly catch these errors.
Validate Now1. Trailing Commas
You might have noticed that JavaScript and many modern programming languages permit trailing commas, but JSON specification is stricter. A trailing comma after the final property or array element will cause parsing to fail.
{
"name": "John",
"email": "john@example.com",
"age": 28,
}
{
"name": "John",
"email": "john@example.com",
"age": 28
}
The same rule applies to arrays:
[
"apple",
"banana",
"orange",
]
[
"apple",
"banana",
"orange"
]
2. Single Quotes Instead of Double Quotes
This confusion often arises because JavaScript uses both single and double quotes interchangeably. However, JSON is stricter and only accepts double quotes to delimit strings and keys.
{
'title': 'Welcome',
'description': 'This is an article',
'author': 'Jane Doe'
}
{
"title": "Welcome",
"description": "This is an article",
"author": "Jane Doe"
}
3. Unquoted Keys
JavaScript's object literal syntax allows you to omit quotes for simple keys, but JSON does not. Every key must be wrapped in double quotes.
{
name: "Alice",
email: "alice@example.com",
isActive: true
}
{
"name": "Alice",
"email": "alice@example.com",
"isActive": true
}
4. Missing Commas Between Properties
When you have multiple properties or array elements, each must be separated by a comma. Omitting these separators is a common typo that breaks the entire document.
{
"id": 1
"name": "Product A"
"price": 29.99
}
{
"id": 1,
"name": "Product A",
"price": 29.99
}
The same applies to array elements:
[
{ "id": 1, "name": "Item 1" }
{ "id": 2, "name": "Item 2" }
{ "id": 3, "name": "Item 3" }
]
[
{ "id": 1, "name": "Item 1" },
{ "id": 2, "name": "Item 2" },
{ "id": 3, "name": "Item 3" }
]
5. Comments in JSON (Not Allowed)
// nor /* */ style comments are permitted. This is a common source of confusion for developers coming from other languages.
While JSON5 (an extended specification) does support comments, strict JSON does not. If you need configuration with comments, consider using YAML, TOML, or JSON5 instead. Alternatively, document your JSON structure separately.
{
// This is the user ID
"id": 42,
/* User's full name */
"name": "Bob Smith"
}
{
"id": 42,
"name": "Bob Smith",
"_comment": "This is the user record for Bob Smith"
}
If you need to preserve documentation, consider keeping comments in a separate markdown file, or use a configuration format that supports comments like YAML or TOML.
6. Undefined Values (Not Valid JSON)
undefined is not valid JSON. Serializing objects with undefined properties will silently omit those properties.
In JavaScript, undefined is a valid value, but JSON has no representation for it. When you encounter an undefined value, use null instead, which is JSON's explicit way to represent "no value."
{
"name": "Charlie",
"nickname": undefined,
"age": null
}
{
"name": "Charlie",
"nickname": null,
"age": null
}
Another approach is to simply omit the property if it has no value:
{
"name": "Charlie",
"age": null
}
7. Leading Zeros in Numbers
JSON numbers should not have leading zeros. If you're formatting numbers like IDs or codes with leading zeros, store them as strings instead.
{
"zipcode": 01234,
"employeeId": 007,
"productCode": 0456
}
{
"zipcode": "01234",
"employeeId": "007",
"productCode": "0456"
}
Alternatively, if these are genuinely numeric values without leading zeros:
{
"zipcode": 1234,
"employeeId": 7,
"productCode": 456
}
8. Unescaped Special Characters in Strings
Special characters need to be properly escaped using backslash notation. This includes quotes, newlines, tabs, and other control characters.
{
"quote": "She said "Hello"",
"path": "C:\Users\Documents",
"multiline": "Line 1
Line 2"
}
{
"quote": "She said \"Hello\"",
"path": "C:\\Users\\Documents",
"multiline": "Line 1\nLine 2"
}
Common escape sequences in JSON:
\"— Double quote\\— Backslash\n— Newline\t— Tab\r— Carriage return\b— Backspace\f— Form feed\uXXXX— Unicode character (where XXXX is the hex code)
Validation Tools Save Time
While understanding these errors is essential, manually reviewing JSON can be tedious. A good JSON validator catches all of these issues instantly. SnapUtils' JSON Formatter highlights syntax errors and shows you exactly where the problem is, complete with line numbers.
By mastering these common mistakes, you'll write cleaner, more reliable JSON and spend less time debugging. Keep this guide bookmarked for quick reference the next time you encounter a JSON parsing error.
Ready to validate your JSON?
Paste your JSON and let SnapUtils identify errors instantly. No installation required.
Validate Your JSON