What Makes JSON Invalid? The 7 Most Common JSON Syntax Errors
JSON is strict. Patterns that work fine in JavaScript object literals silently break JSON parsers. These are the seven errors that account for the vast majority of "Unexpected token" and "JSON parse error" messages.
1. Trailing comma
The most common JSON error. JavaScript allows trailing commas; JSON does not.
// ❌ Invalid JSON
{
"name": "Alice",
"age": 30, ← trailing comma
}
// ✅ Valid JSON
{
"name": "Alice",
"age": 30
}2. Single-quoted strings
JSON requires double quotes. Single quotes are a JavaScript convenience, not part of the JSON spec.
// ❌ Invalid
{ 'name': 'Alice' }
// ✅ Valid
{ "name": "Alice" }3. Unquoted keys
Object keys must be quoted strings in JSON. Unquoted keys are valid in JavaScript ({ name: "Alice" }) but invalid in JSON.
// ❌ Invalid JSON
{ name: "Alice" }
// ✅ Valid JSON
{ "name": "Alice" }4. Comments
JSON has no comment syntax. Neither // single-line nor /* block */ comments are valid. If you need comments in config files, consider JSONC (JSON with Comments, used by VS Code), YAML, or TOML instead.
5. NaN, Infinity, and undefined
These are valid JavaScript values but not valid JSON. JSON.stringify() silently converts them:
NaN→nullInfinity→nullundefined→ key is omitted entirely
This means round-tripping through JSON can silently lose or change data if your objects contain these values.
6. Unescaped control characters in strings
Literal newlines, tabs, and other control characters (U+0000 to U+001F) inside string values must be escaped. A raw newline in a string value is invalid.
// ❌ Invalid — literal newline in string
{ "message": "line one
line two" }
// ✅ Valid — escaped newline
{ "message": "line one\nline two" }7. Numbers: hex, leading zeros, bare decimal point
JSON numbers must be decimal only. Hexadecimal literals, octal literals, and numbers with a leading decimal point are not valid.
// ❌ Invalid JSON numbers
{ "a": 0xFF, "b": 077, "c": .5, "d": 1. }
// ✅ Valid
{ "a": 255, "b": 63, "c": 0.5, "d": 1.0 }Quick fix
Paste your broken JSON into the validator below — it highlights the exact line and column of the error and explains what went wrong.
Try it yourself
Use the free browser-based JSON Formatter & Validator on DevBench — no signup, runs entirely in your browser.
Open JSON Formatter & Validator