10 Most Common JSON Errors and How to Fix Them
Master JSON syntax by learning to identify and fix the most frequent errors that trip up developers. Complete with examples, solutions, and prevention tips.
✅ Valid JSON
- • Double quotes for strings and keys
- • No trailing commas
- • Proper number formats
- • Balanced brackets and braces
❌ Invalid JSON
- • Single quotes or unquoted keys
- • Comments (// or /* */)
- • undefined values
- • Functions or complex objects
Extra commas before closing brackets or braces
❌ Invalid JSON
{
"name": "John",
"age": 30,
}✅ Valid JSON
{
"name": "John",
"age": 30
}💡 Solution
Remove the trailing comma after the last property or array element.
Prevention Tips:
- • Use a JSON formatter to automatically detect trailing commas
- • Enable linting in your code editor to catch these errors
- • Be extra careful when copying/pasting JSON objects
Object keys must be wrapped in double quotes
❌ Invalid JSON
{
name: "John",
age: 30
}✅ Valid JSON
{
"name": "John",
"age": 30
}💡 Solution
Always wrap object keys in double quotes, even if they look like valid identifiers.
Prevention Tips:
- • JSON is stricter than JavaScript object notation
- • Use a JSON validator to catch unquoted keys
- • Remember: JSON keys are always strings
JSON only accepts double quotes for strings
❌ Invalid JSON
{
'name': 'John',
'age': 30
}✅ Valid JSON
{
"name": "John",
"age": 30
}💡 Solution
Replace all single quotes with double quotes for both keys and string values.
Prevention Tips:
- • Use find/replace to convert single quotes to double quotes
- • Be careful with escaped quotes inside strings
- • JSON parsers are strict about quote types
Unclosed arrays or objects cause parsing errors
❌ Invalid JSON
{
"users": [
{"name": "John"},
{"name": "Jane"}
"total": 2
}✅ Valid JSON
{
"users": [
{"name": "John"},
{"name": "Jane"}
],
"total": 2
}💡 Solution
Ensure every opening bracket [ has a closing bracket ] and every opening brace { has a closing brace }.
Prevention Tips:
- • Use proper indentation to visualize structure
- • Count opening and closing brackets/braces
- • Use a code editor with bracket matching
Incorrect use of backslashes in strings
❌ Invalid JSON
{
"path": "C:\Users\John\Documents",
"regex": "\d+"
}✅ Valid JSON
{
"path": "C:/Users/John/Documents",
"regex": "\\d+"
}💡 Solution
Properly escape backslashes by doubling them (\\) or use forward slashes where appropriate.
Prevention Tips:
- • Common escape sequences: \n, \t, \r, \", \\
- • Use raw strings in your programming language when building JSON
- • Test escape sequences in a JSON validator
JavaScript undefined is not valid JSON
❌ Invalid JSON
{
"name": "John",
"middleName": undefined,
"age": null
}✅ Valid JSON
{
"name": "John",
"middleName": null,
"age": null
}💡 Solution
Use null for empty values, or omit the property entirely. Never use undefined in JSON.
Prevention Tips:
- • JSON only supports: string, number, boolean, null, object, array
- • undefined is a JavaScript concept, not JSON
- • Consider omitting properties instead of setting them to null
JSON doesn't support comments
❌ Invalid JSON
{
// User information
"name": "John",
/* Age in years */
"age": 30
}✅ Valid JSON
{
"name": "John",
"age": 30,
"_comment": "User information with age in years"
}💡 Solution
Remove comments or use a special property like '_comment' for documentation.
Prevention Tips:
- • Use JSONC (JSON with Comments) for configuration files if supported
- • Document your JSON schema separately
- • Consider using a more flexible format like YAML for config files
Multiple properties with the same key name
❌ Invalid JSON
{
"name": "John",
"age": 30,
"name": "Jane"
}✅ Valid JSON
{
"firstName": "John",
"age": 30,
"lastName": "Jane"
}💡 Solution
Ensure all object keys are unique within the same object.
Prevention Tips:
- • JSON parsers typically use the last occurrence
- • Use a linter to detect duplicate keys
- • Consider using arrays for multiple similar values
Incorrectly formatted numeric values
❌ Invalid JSON
{
"price": 19.99.0,
"count": 01,
"percentage": .5
}✅ Valid JSON
{
"price": 19.99,
"count": 1,
"percentage": 0.5
}💡 Solution
Follow JSON number format rules: no leading zeros, decimal point needs digits on both sides.
Prevention Tips:
- • Valid: 123, -123, 1.23, -1.23, 1.23e10
- • Invalid: 01, .5, 1., 1.23.45
- • Use parseFloat() to ensure proper number formatting
Missing commas or brackets in arrays
❌ Invalid JSON
{
"colors": ["red" "blue", "green"],
"numbers": [1, 2, 3,]
}✅ Valid JSON
{
"colors": ["red", "blue", "green"],
"numbers": [1, 2, 3]
}💡 Solution
Separate array elements with commas and avoid trailing commas.
Prevention Tips:
- • Every array element except the last needs a comma
- • Arrays can contain mixed types in JSON
- • Empty arrays [] are valid
Ready to Fix Your JSON?
Use our free JSON tools to validate, format, and debug your JSON data. Get instant error detection with helpful suggestions.