Common JSON Syntax Errors and How to Fix Them
Nine mistakes cause almost every "invalid JSON" error you'll ever see. Here's each one, with the fix.
Almost every "invalid JSON" error traces back to one of a small set of recurring mistakes - most of them stemming from JSON's similarity to (but stricter rules than) JavaScript object literals. Here's each one, with a before/after example.
1. Trailing commas
// Invalid
{"a": 1, "b": 2,}
// Valid
{"a": 1, "b": 2}JavaScript object literals tolerate a trailing comma; JSON does not. This is the single most common cause of invalid JSON, often introduced when a field is deleted and the preceding comma is left behind.
2. Single quotes
// Invalid
{'name': 'Alice'}
// Valid
{"name": "Alice"}JSON requires double quotes, full stop - for both keys and string values.
3. Unquoted keys
// Invalid
{name: "Alice"}
// Valid
{"name": "Alice"}4. Missing commas between items
// Invalid
{"a": 1 "b": 2}
// Valid
{"a": 1, "b": 2}5. Mismatched braces or brackets
// Invalid
{"items": [1, 2, 3}
// Valid
{"items": [1, 2, 3]}An array must close with ], and an object with } - mixing them up is easy to miss in deeply nested structures.
6. Comments
// Invalid
{
"name": "Alice" // the user's name
}
// Valid - move the note elsewhere, JSON has no comment syntax
{
"name": "Alice"
}Standard JSON has no comment syntax at all - not // and not /* */. If you need comments, you're likely working with JSON5 or JSONC, which are supersets - see JSON vs JSON5: What's the Difference? for that distinction.
7. Invalid escape sequences in strings
// Invalid - backslash isn't escaped
{"path": "C:\Users\alice"}
// Valid
{"path": "C:\\Users\\alice"}A literal backslash inside a JSON string must be escaped as \\ - a single unescaped backslash followed by an unrecognized character is invalid.
8. Numbers with a leading zero or plus sign
// Invalid
{"code": 007}
{"count": +5}
// Valid
{"code": "007"}
{"count": 5}JSON numbers can't have leading zeros (other than the number 0 itself) or an explicit plus sign. If you need to preserve a leading zero, like a US ZIP code, store it as a string.
9. Smart/curly quotes
// Invalid - curly quotes from a word processor
{“name”: “Alice”}
// Valid - straight double quotes
{"name": "Alice"}This one is easy to miss visually - curly quotes look almost identical to straight quotes at a glance, but a JSON parser treats them as completely different, invalid characters. They usually sneak in when JSON is copy-pasted out of a word processor or a rich-text field.
Quick reference table
| Mistake | Fix |
|---|---|
| Trailing comma | Remove the comma before } or ] |
| Single quotes | Replace with double quotes |
| Unquoted keys | Wrap every key in double quotes |
| Missing comma | Add a comma between items |
| Mismatched brackets | Match { with } and [ with ] |
| Comments | Remove them - not supported in standard JSON |
| Unescaped backslash | Escape as \\ |
| Leading zero/plus sign | Store as a string, or remove the sign |
| Smart quotes | Replace with straight double quotes |
The JSON Formatter catches every one of these automatically, reports the exact line and column, and can suggest a one-click fix for trailing commas, single quotes, and unquoted keys.
Summary
Nearly every JSON syntax error comes from one of these nine patterns - most of them differences from JavaScript's more permissive object literal syntax. Once you recognize the pattern, the fix is almost always a one-character change.
Frequently asked questions
- Why is a trailing comma not allowed in JSON?
- The JSON specification simply doesn't include trailing commas as valid syntax, unlike JavaScript object literals which do allow them - this is one of the most common sources of confusion since the two look so similar.
- Can JSON keys be unquoted?
- No - every key in a JSON object must be a double-quoted string. {name: "Alice"} is invalid; {"name": "Alice"} is required.
- Does JSON support single quotes?
- No - JSON requires double quotes for both strings and keys. Single quotes are valid in JavaScript object literals and many other languages, but not in the JSON spec itself.
Try it yourself
The tool that pairs with this guide.
Did this help you untangle that JSON?
If these free developer tools save you time, consider buying me a byte. Your support helps keep DevCraftKit free and growing.
Related articles
How to Format JSON: Pretty Print and Read JSON Easily
Formatting turns a wall of JSON into something you can actually scan. Here's what it does and how to do it.
Published
JSON Validator: How to Find and Fix Invalid JSON
A single misplaced comma breaks the whole document. Here's how validation finds it and what the common causes are.
Published
JSON Pretty Print vs Minify: What's the Difference?
Same data, two shapes - one for humans, one for the network. Here's when each one is the right choice.
Published