JSON errors are among the most common bugs in web development. This guide covers the issues you'll encounter most often and how to fix them quickly.
Top 10 JSON Errors
1. Trailing Commas
{
"name": "Alice", ← Remove this comma
}
Fix: Remove trailing commas after the last property.
2. Single Quotes
{'name': 'Alice'} ← Wrong
Fix: Always use double quotes for strings and keys.
3. Unquoted Keys
{name: "Alice"} ← Wrong
Fix: All keys must be in double quotes: {"name": "Alice"}
4. Comments in JSON
{
// This is not valid JSON
"name": "Alice"
}
Fix: JSON doesn't support comments. Remove them or use JSONC format.
5. Special Characters in Strings
{"text": "Line 1
Line 2"} ← Newlines must be escaped
Fix: Use \n for newlines: "Line 1\nLine 2"
6. Undefined and NaN Values
{"value": undefined} ← Not valid JSON
Fix: Use null instead: {"value": null}
7. Hex Numbers
{"color": 0xFF0000} ← Not valid JSON
Fix: Use strings for hex: {"color": "#FF0000"}
8. Incorrect Nesting
{"users": {"name": "Alice"},} ← Extra brace
Fix: Match all opening and closing brackets carefully.
9. Unicode Issues
{"emoji": "🎉"} ← Usually works, but escape if needed
10. BOM Characters
Files saved with BOM can cause parse errors. Fix: Save as UTF-8 without BOM.
Debugging Workflow
Prevention Tips
JSON.stringify() instead of manual construction