"Invalid JSON" is the most common error in web development. Almost always, the cause is one of ten small mistakes. Here's the diagnostic checklist — start at the top and work down.
1. Trailing comma
The #1 cause of JSON parsing failures, by a huge margin.
// Invalid - trailing comma after "Bob"
{ "users": [{ "name": "Alice" }, { "name": "Bob" },] }
// Valid
{ "users": [{ "name": "Alice" }, { "name": "Bob" }] }
Why it trips people up: modern JavaScript allows trailing commas in object literals and array literals. Python allows them. Many programmers internalize "trailing comma OK" and apply it to JSON, where it isn't.
Fix: Remove any comma that comes immediately before a closing } or ]. Search-and-replace ,} with } and ,] with ] (handling whitespace appropriately).
2. Single quotes instead of double quotes
// Invalid
{ 'name': 'Alice' }
// Valid
{ "name": "Alice" }
JSON requires double quotes for every string and every object key. Single quotes are not allowed anywhere.
Common cause: copying a JavaScript or Python object literal into a place expecting JSON. Both languages allow single quotes; JSON doesn't.
Fix: Replace all single quotes with double quotes. Watch out for apostrophes inside strings — those need to be escaped or you need to use double quotes outside.
3. Unquoted object keys
// Invalid
{ name: "Alice", age: 30 }
// Valid
{ "name": "Alice", "age": 30 }
JSON requires every object key in double quotes, even if it's a simple identifier-like name. JavaScript object literal syntax allows unquoted keys, JSON doesn't.
Fix: Wrap every key in double quotes.
4. Comments
// Invalid - no comments allowed
{
// This is the user name
"name": "Alice"
}
// Also invalid
{
/* The user name */
"name": "Alice"
}
JSON has no comment syntax. Both // line comments and /* */ block comments cause parse errors.
Fix: Remove all comments. If you need them, use a JSONC-aware parser (for VS Code config files) or switch to JSON5 or YAML.
5. Special values: NaN, Infinity, undefined
// All invalid
{ "value": NaN }
{ "value": Infinity }
{ "value": undefined }
// Valid alternatives
{ "value": null }
{ "value": "NaN" } // as a string sentinel
These exist in JavaScript but not in JSON. NaN and Infinity in particular trip up code that serializes calculation results without checking for them first.
Fix: Before serializing, replace special values with null or string sentinels. JSON.stringify in JavaScript silently converts these to null already, but the reverse direction (parsing) won't accept them.
6. Unescaped characters in strings
// Invalid - unescaped double quote in string
{ "message": "She said "hello"" }
// Valid - escaped
{ "message": "She said \"hello\"" }
Inside a JSON string, certain characters must be escaped: \ (backslash), " (double quote), and control characters (newline, tab, etc.).
Fix: Escape backslashes as \\, quotes as \", newlines as \n, tabs as \t. If you're constructing JSON in code, use a JSON library — don't concatenate strings manually.
7. Smart quotes from a word processor
// Looks valid but invalid - "smart" curly quotes
{ "name": "Alice" }
// ^ ^ ← these aren't ASCII double quotes
If you copy JSON from Word, Pages, Google Docs, or even some terminal emulators, regular ASCII quotes (") may have been replaced with "smart" curly quotes (" and "). They look almost identical but are different Unicode characters, and JSON parsers reject them.
Fix: Open the text in a code editor that displays Unicode clearly. Replace curly quotes with straight quotes. Disable auto-quote substitution in your word processor before pasting JSON next time.
8. Byte-order mark (BOM)
Some text editors save files with a UTF-8 BOM (three invisible bytes at the start). Many JSON parsers reject this:
// What's actually in the file (invisible BOM shown as ⟨BOM⟩)
⟨BOM⟩{ "name": "Alice" }
Fix: Save without BOM. In VS Code, the bottom-right status bar shows the encoding — click it and choose "Save with Encoding" → UTF-8 (without BOM). On the command line: sed -i '1s/^\xEF\xBB\xBF//' file.json.
9. Mismatched brackets
// Invalid - missing closing }
{ "user": { "name": "Alice" }
// Invalid - extra ]
{ "items": [1, 2, 3]] }
The parser will fail at the end of input (for missing closing) or at the unexpected character (for extra closing). The error message typically gives you a line/column near where the imbalance was detected — which isn't always where the actual missing bracket should be.
Fix: Format the JSON with our formatter first. Pretty-printing makes bracket mismatches visually obvious. Most code editors also have bracket-matching highlighting that shows you where each bracket opens and closes.
10. Trailing data after a valid JSON value
// Invalid - extra content after the closing brace
{ "name": "Alice" }
Some unexpected text here
A JSON document is exactly one value. Anything after the value (other than whitespace) is an error. This often happens when concatenating two JSON documents accidentally, or when a stream is split incorrectly.
Fix: Trim everything after the closing brace or bracket of the top-level value. If you have multiple JSON values to join, format them as a JSON array ([value1, value2, value3]) or as JSON Lines (one value per line, each line a complete JSON document).
Bonus: leading zeros in numbers
// Invalid - JSON numbers can't have leading zeros
{ "code": 007 }
// Valid
{ "code": "007" } // as a string
{ "code": 7 } // as the integer 7
JSON numbers must be written canonically: no leading zeros (except 0 itself), no trailing decimal point (5. is invalid; 5.0 is fine).
Debugging workflow
When you have invalid JSON and don't know why, this workflow finds it fastest:
- Paste the JSON into our validator — it points you to the exact line and column of the error.
- Look at the character at that position, plus the few characters before. The problem is almost always within a few characters of where the parser failed.
- Cross-check against this list. The first match is usually the cause.
- If nothing matches, check for invisible characters: smart quotes, BOM, non-breaking spaces, zero-width spaces. Open the file in a hex editor or a code editor with Unicode visualization.
Wrap-up
JSON syntax is strict but the failure modes are predictable. Trailing commas and single quotes account for at least half of all "invalid JSON" errors. Once you've fixed each of these once, you'll recognize them instantly the next time.