Learn to identify and fix the most common JSON parsing errors. From trailing commas to encoding issues, master JSON troubleshooting like a pro.
JSON errors can bring your application to a grinding halt. Whether you are consuming an API, reading a config file, or parsing user input, understanding common JSON errors saves hours of debugging time. Let us explore the most frequent mistakes and their solutions.
The most common JSON error is leaving a comma after the last element.
Wrong:
{ "name": "John", "age": 30, }
Right:
{ "name": "John", "age": 30 }
Fix: Remove trailing commas before the closing brace or bracket. Our JSON formatter automatically detects and highlights these errors.
JSON requires double quotes for strings and keys.
Wrong:
{ 'name': 'John', 'age': 30 }
Right:
{ "name": "John", "age": 30 }
Fix: Replace all single quotes with double quotes. Be careful with nested quotes in strings.
Object keys must always be quoted in JSON.
Wrong:
{ name: "John", age: 30 }
Right:
{ "name": "John", "age": 30 }
Fix: Wrap all object keys in double quotes.
JavaScript undefined is not valid in JSON.
Wrong:
{ "name": "John", "nickname": undefined }
Right:
{ "name": "John", "nickname": null }
Fix: Replace undefined with null or omit the property entirely.
Standard JSON does not support comments.
Wrong:
{ "name": "John" /* user name */ }
Right:
{ "name": "John" }
Fix: Remove comments or use JSON-C format if your parser supports it.
Invalid escape sequences break JSON parsing.
Wrong:
{ "text": "Hello \xWorld" }
Right:
{ "text": "Hello \u0057orld" }
Fix: Use proper Unicode escape sequences (\uXXXX) or valid escape characters.
Special characters must be escaped.
Wrong:
{ "text": "Line 1
Line 2" }
Right:
{ "text": "Line 1\nLine 2" }
Fix: Escape newlines (\n), tabs (\t), and quotes (") properly.
Objects that reference themselves cannot be serialized.
Wrong:
const obj = {}; obj.self = obj; JSON.stringify(obj);
Right:
Remove circular references before serialization or use a replacer function.
Fix: Use a library like circular-json or implement custom serialization.
JSON does not support special numeric values.
Wrong:
{ "value": NaN, "big": Infinity }
Right:
{ "value": null, "big": null }
Fix: Replace NaN and Infinity with null or use a custom JSON serializer.
UTF-8 is the standard encoding for JSON.
Problem: Files saved with BOM or Windows-1252 encoding. Solution: Ensure all JSON files are saved as UTF-8 without BOM.
Most JSON errors are preventable with proper tooling and awareness. Use our online JSON validator to catch errors before they reach production, and save yourself hours of debugging time.