Common JSON Errors and How to Fix Them
Invalid JSON is one of the most common causes of API failures. A single missing quote or extra comma can break your entire application. Here are the errors you'll encounter most often and exactly how to fix each one.
1. Missing Quotes Around Keys
In JSON, all keys must be wrapped in double quotes. This is different from JavaScript objects where quotes are optional.
Wrong:
{
name: "John",
age: 30
}
Correct:
{
"name": "John",
"age": 30
}
2. Trailing Commas
JSON does not allow trailing commas after the last item in an object or array. This is a common mistake when copying from JavaScript.
Wrong:
{
"items": ["apple", "banana", "orange",],
"count": 3,
}
Correct:
{
"items": ["apple", "banana", "orange"],
"count": 3
}
3. Single Quotes Instead of Double Quotes
JSON requires double quotes for strings. Single quotes are not valid JSON syntax.
Wrong:
{
'name': 'John',
'email': 'john@example.com'
}
Correct:
{
"name": "John",
"email": "john@example.com"
}
4. Mismatched Brackets
Every opening brace { must have a closing brace }, and every opening
bracket [ must have a closing bracket ]. This error often happens with
nested structures.
Wrong:
{
"users": [
{"name": "John"},
{"name": "Jane"}
}
Correct:
{
"users": [
{"name": "John"},
{"name": "Jane"}
]
}
5. Unescaped Special Characters
Certain characters inside strings must be escaped with a backslash: ",
\, and control characters like newlines.
Wrong:
{
"message": "He said "Hello" to me"
}
Correct:
{
"message": "He said \"Hello\" to me"
}
6. Using Undefined or Comments
JSON doesn't support undefined or comments. Use null for missing
values.
Wrong:
{
"name": "John",
// This is a comment
"age": undefined
}
Correct:
{
"name": "John",
"age": null
}
Validate Your JSON Instantly
Paste your JSON to find and fix errors automatically.
Use JSON FormatterHow to Find JSON Errors Quickly
- Use a validator. Paste your JSON into a JSON formatter to see the exact error location.
- Check line numbers. Error messages usually point to where the parser failed, which is often right after the actual mistake.
- Validate incrementally. If you're building JSON manually, validate each section as you add it.
- Use proper tools. Code editors with JSON support will highlight syntax errors before you run your code.