Most "invalid JSON" errors come from one of eight causes. Once you've seen each one, you'll recognize them instantly. This is a quick reference: cause, error message you'll typically see, and the fix.
1. Trailing commas
Bad:
{
"name": "Alice",
"age": 30,
}
Error: "Unexpected token } in JSON at position N" (V8/Node), "Expecting property name enclosed in double quotes" (Python).
Fix: Remove the comma after 30. JSON does not allow trailing commas in objects or arrays. JavaScript object literals do allow them, which is why this is the most common mistake. If you need trailing commas (often for cleaner diffs), use JSON5 or JSONC at the source and convert to strict JSON for transmission.
2. Single quotes instead of double quotes
Bad:
{ 'name': 'Alice' }
Error: "Unexpected token ' in JSON at position 2".
Fix: JSON strings must use double quotes. Single quotes are valid in JavaScript, Python, and many other languages — but not JSON.
3. Unquoted keys
Bad:
{ name: "Alice" }
Error: "Unexpected token n in JSON at position 2".
Fix: Object keys must be strings, in double quotes. {"name": "Alice"}. JavaScript object literals can have unquoted keys; JSON cannot.
4. Unescaped special characters in strings
Bad:
{ "message": "He said "hi" to me" }
Error: "Unexpected token h in JSON at position 16".
Fix: Escape inner quotes with backslash. {"message": "He said \"hi\" to me"}. Other characters that need escaping inside strings: backslash \\, newline \n, tab \t, carriage return \r, and forward slash \/ (optional but allowed). Control characters (U+0000 through U+001F) must be escaped using \uXXXX.
5. Comments
Bad:
{
"name": "Alice", // user's name
"age": 30
}
Error: "Unexpected token / in JSON at position N".
Fix: Remove the comment. JSON does not support // or /* */ comments. For configuration files where comments are useful, use JSONC or JSON5, or YAML. Convert to strict JSON before transmitting.
6. Numbers in invalid formats
Bad:
{ "amount": .5 }
{ "id": 007 }
{ "value": +42 }
{ "rate": 5. }
Error: Varies, often "Unexpected number" or "Unexpected token".
Fix: JSON numbers must start with a digit or minus sign. 0.5 not .5. No leading zeros except 0 itself, so 7 not 007. No leading +. No trailing decimal point — write 5.0 not 5.. NaN and Infinity are not valid JSON either; they must be represented as strings or null.
7. UTF-8 BOM at the start of file
Bad: A file that starts with the byte sequence EF BB BF (UTF-8 byte order mark) before the opening brace.
Error: "Unexpected token in JSON at position 0" — the error position is 0, which is the giveaway. Some parsers display the BOM as garbage characters.
Fix: Save the file as "UTF-8 without BOM". Most editors have this as an option. In Node: JSON.parse(content.replace(/^\uFEFF/, '')). Per RFC 8259, JSON should be encoded as UTF-8 without BOM.
8. Smart quotes from copy-paste
Bad:
{ "name": "Alice" }
Looks fine — but the quotes are U+201C (left double quotation mark) and U+201D (right double quotation mark), not U+0022 (regular double quote). This happens when you copy from Word, Google Docs, Slack, or any tool with "smart quote" autocorrect.
Error: "Unexpected token " in JSON at position 0" — with a curly quote shown.
Fix: Find-and-replace curly quotes with straight ones. Most code editors have a setting to disable smart-quote autocorrect when you're editing source files. The JSON validator will catch this and point you to the exact character.
Bonus: missing comma between elements
Bad:
{
"name": "Alice"
"age": 30
}
Error: "Unexpected string in JSON at position N".
Fix: Add the comma after "Alice". Every key-value pair except the last must be followed by a comma.
Debugging workflow
When you have invalid JSON and don't know why:
- Paste it into the validator — it points you to the exact line and column.
- Look at the character at that position and the few before it. 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.
For more on JSON's data model, see our JSON data types guide.