Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool
Common JSON Syntax Errors and How to Fix Them
JSON (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse. Despite its simplicity, JSON syntax errors are common and can be frustrating to debug. Let's look at the most frequent JSON syntax errors and how to fix them.
1. Missing or Extra Commas
The most common JSON error is incorrect comma usage. Each item in an array or property in an object must be followed by a comma, except for the last one.
Incorrect:
{ "name": "John", "age": 30, "city": "New York" "country": "USA" }
Corrected:
{ "name": "John", "age": 30, "city": "New York", "country": "USA" }
Incorrect:
{ "fruits": [ "apple", "banana", "orange", ] }
Corrected:
{ "fruits": [ "apple", "banana", "orange" ] }
2. Unclosed Brackets and Braces
Every opening bracket or brace must have a matching closing one. Missing brackets are hard to spot in large JSON files.
Incorrect:
{ "person": { "name": "Alice", "hobbies": ["reading", "hiking" } }
Corrected:
{ "person": { "name": "Alice", "hobbies": ["reading", "hiking"] } }
3. Using Single Quotes Instead of Double Quotes
JSON requires double quotes for both property names and string values. Single quotes are not valid in JSON.
Incorrect:
{ 'name': 'Bob', 'email': 'bob@example.com' }
Corrected:
{ "name": "Bob", "email": "bob@example.com" }
4. Missing Quotes Around Property Names
Unlike JavaScript objects, JSON requires quotes around property names.
Incorrect:
{ name: "Charlie", age: 25 }
Corrected:
{ "name": "Charlie", "age": 25 }
5. Invalid Escape Sequences
If you need to include quotes or special characters in strings, they must be properly escaped.
Incorrect:
{ "message": "He said "Hello" to me", "path": "C:\Users\Documents" }
Corrected:
{ "message": "He said \"Hello\" to me", "path": "C:\\Users\\Documents" }
6. Invalid Number Formats
JSON supports numbers without quotes, but there are restrictions:
- No leading + sign
- No leading zeros (except for decimal numbers less than 1)
- No trailing decimal point
Incorrect:
{ "price": +42.00, "quantity": 007, "discount": 10. }
Corrected:
{ "price": 42.00, "quantity": 7, "discount": 10.0 }
7. Real-World Example: API Response
Let's look at a real-world example of an invalid API configuration that might cause errors:
Incorrect:
{ "api_config": { "base_url": "https://api.example.com/v1", "timeout": 30, "retry": { "max_attempts": 3 "backoff_ms": 1000, }, "auth": { "type": 'oauth2', "client_id": "abc123" } } }
Corrected:
{ "api_config": { "base_url": "https://api.example.com/v1", "timeout": 30, "retry": { "max_attempts": 3, "backoff_ms": 1000 }, "auth": { "type": "oauth2", "client_id": "abc123" } } }
How to Prevent and Fix JSON Errors
- Use a JSON formatter to validate and prettify your JSON
- Check for matching pairs of braces and brackets
- Ensure correct comma placement (after each item except the last)
- Always use double quotes for strings and property names
- Properly escape special characters
- Pay attention to error messages - they often point to the exact line with the problem
Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool