How to fix common JSON errors
You paste a response into your code, call JSON.parse(), and get “Unexpected token”. JSON is strict: one stray comma or the wrong kind of quote makes the whole document invalid. The good news is that almost every JSON error comes from the same ten mistakes, and the error message tells you exactly where to look — once you know how to read it.
Step 1: read the error message properly
Every parser reports where it gave up. The wording differs by language, but the information is the same:
| Where | Typical message |
|---|---|
| Chrome / Node.js | Expected double-quoted property name in JSON at position 7 (line 1 column 8) |
| Firefox | JSON.parse: expected property name or '}' at line 1 column 8 |
| Python | JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 8 (char 7) |
The position counts characters from the start of the text (starting at 0); the line and column are easier for humans. The real mistake is usually at or just before that spot — the parser only notices a problem when the next character doesn’t fit.
Tip: paste your JSON into the JSON Formatter and press Validate. It shows the line and column and moves your cursor straight to the problem.
Step 2: check the ten usual suspects
1. Trailing commas
JavaScript allows a comma after the last item; JSON does not.
{ "name": "Rahim", "age": 28, } ✗
{ "name": "Rahim", "age": 28 } ✓
2. Single quotes
Strings and keys must use double quotes ". 'Dhaka' is invalid.
3. Keys without quotes
{ name: "Rahim" } is a valid JavaScript object but invalid JSON. Every key needs double quotes: { "name": "Rahim" }.
4. Comments
JSON has no comments — neither // … nor /* … */. If you need notes in a config file, use a field such as "_comment", or a format that supports comments (JSONC, YAML).
5. A missing comma between items
{ "city": "Dhaka" "zip": "1216" } ✗ (comma missing after "Dhaka")
6. Mismatched brackets
Every { needs a } and every [ needs a ], in the right order. “Unexpected end of JSON input” almost always means something was never closed — often because the text was cut off (a truncated log line or a half-copied response).
7. Unescaped characters inside strings
A double quote inside a string must be written \", a backslash as \\, and a real line break as \n. Windows paths are a classic trap: "C:\Users\rahim" is invalid; write "C:\\Users\\rahim".
8. JavaScript values that JSON doesn’t have
undefined, NaN, Infinity, functions and dates are not JSON. Use null for missing values and ISO strings such as "2026-09-27T10:00:00Z" for dates.
9. Python’s True, False and None
If you copied a Python print() of a dict, you’ll see True, False, None and single quotes. JSON needs true, false, null and double quotes. In Python, use json.dumps(data) instead of print(data).
10. Invisible characters
“Smart” quotes (“ ”) from Word or chat apps, a byte-order mark at the start of a file, or a non-breaking space can all break parsing while looking perfectly normal. If the error points at a character you can’t see, retype the quotes around that spot.
Step 3: prevent it next time
- Never build JSON by gluing strings together. Use
JSON.stringify()in JavaScript,json.dumps()in Python or your language’s JSON library — they handle quotes and escaping for you. - Check the response before parsing it. Many “Unexpected token <” errors are an HTML error page (starting with
<!doctype html>) returned instead of JSON. Log the raw text and the HTTP status first. - Validate in your editor. VS Code and most IDEs highlight JSON errors as you type in
.jsonfiles.
FAQ
What does “Unexpected token < in JSON at position 0” mean?
The text you parsed starts with < — it is HTML, not JSON. Usually the server returned an error page (404, 500) or a login page. Check the URL and the HTTP status code.
Are duplicate keys an error?
Most parsers accept them and silently keep the last value, which hides bugs. The JSON standard says keys should be unique, so treat duplicates as a mistake.
Is my data safe in the online formatter?
Yes. JSON Bondhu processes everything in your browser; nothing you paste is uploaded.