Introduction
JSON (JavaScript Object Notation) is strict by design. Unlike HTML or JavaScript, which often fail silently or attempt to auto-correct syntax mistakes, a JSON parser will throw an immediate runtime error if even a single character violates the RFC 8259 specification.
Whether you are debugging a REST API response, writing a configuration file, or importing database fixtures, here are the 10 most common JSON syntax errors and how to fix them quickly.
1. Trailing Commas in Objects or Arrays
The Error
A trailing comma occurs when a comma is left after the final key-value pair in an object or after the last element in an array.
❌ Incorrect:
{
"hostname": "localhost",
"port": 5432,
}
The Fix
Remove the comma after the last property.
✅ Correct:
{
"hostname": "localhost",
"port": 5432
}
2. Using Single Quotes Instead of Double Quotes
The Error
In JavaScript, single quotes and double quotes are interchangeable for strings. In standard JSON, only double quotes are valid.
❌ Incorrect:
{
'title': 'Senior Developer',
'department': 'Engineering'
}
The Fix
Replace all single quotes around keys and values with double quotes.
✅ Correct:
{
"title": "Senior Developer",
"department": "Engineering"
}
3. Unquoted Object Keys
The Error
Writing object keys without quotes is common in JavaScript objects, but completely invalid in JSON.
❌ Incorrect:
{
name: "JSON Workshop",
version: 1.0
}
The Fix
Enclose every key in double quotation marks.
✅ Correct:
{
"name": "JSON Workshop",
"version": 1.0
}
4. Including Comments Inside JSON
The Error
Standard JSON specification does not support single-line (//) or multi-line (/* */) comments. Including them will crash standard JSON parsers like JSON.parse().
❌ Incorrect:
{
// Database configuration
"db_host": "127.0.0.1"
}
The Fix
Remove comments entirely, or use JSON5 / JSONC if your framework explicitly supports commented JSON formats.
✅ Correct:
{
"db_host": "127.0.0.1"
}
5. Unescaped Double Quotes Inside String Values
The Error
If a string value contains double quotes without backslash escaping, the parser assumes the string has ended prematurely.
❌ Incorrect:
{
"quote": "He said, "Hello World" before exiting."
}
The Fix
Escape internal quotes with a backslash \".
✅ Correct:
{
"quote": "He said, \"Hello World\" before exiting."
}
6. Invalid Number Formatting
The Error
Leading zeros, fractions without digits, or hexadecimal values are not permitted in JSON numbers.
❌ Incorrect:
{
"code": 007,
"price": .99,
"hex": 0xFF
}
The Fix
Format numbers as standard decimals or integers.
✅ Correct:
{
"code": 7,
"price": 0.99,
"hex": 255
}
7. Using undefined or Functions as Values
The Error
JSON only accepts Strings, Numbers, Booleans, Null, Objects, and Arrays. Functions, undefined, Symbols, and Date objects cannot be serialized directly.
❌ Incorrect:
{
"status": undefined,
"handler": function() {}
}
The Fix
Use null for missing values, or format special types as strings.
✅ Correct:
{
"status": null,
"handler": "disabled"
}
8. Misplaced Brackets or Braces
The Error
Mismatched or missing closing brackets } or ] will break the syntax structure of nested data.
❌ Incorrect:
{
"users": [
{"name": "Alice"},
{"name": "Bob"}
The Fix
Ensure every opening brace { or [ has a matching closing brace } or ].
✅ Correct:
{
"users": [
{"name": "Alice"},
{"name": "Bob"}
]
}
9. Raw Newline Characters Inside Strings
The Error
Literal multiline breaks inside quotes are not allowed in JSON string literals.
❌ Incorrect:
{
"bio": "Developer by day.
Gamer by night."
}
The Fix
Use the escape sequence \n to represent multiline strings.
✅ Correct:
{
"bio": "Developer by day.\nGamer by night."
}
10. NaN or Infinity Values
The Error
Special floating-point values like NaN, Infinity, or -Infinity are not recognized in JSON syntax.
❌ Incorrect:
{
"score": NaN,
"limit": Infinity
}
The Fix
Represent missing calculation values as null or numerical strings.
✅ Correct:
{
"score": null,
"limit": "Infinity"
}
How to Debug JSON Errors Instantly
Instead of hunting down invisible trailing commas manually, paste your data into our free JSON Formatter & Validator. The editor instantly highlights syntax error lines and displays exact character coordinates in real-time.