JSON Wallet

Common JSON Errors and How to Fix Them

10 min read

← All guides

When a JSON parser fails, the error message is often cryptic. Below are the errors you will run into most often, what actually causes them, and how to fix them. You can paste any broken JSON into the JSON Wallet editor to see the exact line and position of the problem, or use the Repair button to fix many of these automatically.

1. Trailing comma

Symptom: "Unexpected token }" or "Trailing comma".
Cause: a comma after the last item in an object or array.

// broken
{ "a": 1, "b": 2, }
// fixed
{ "a": 1, "b": 2 }

2. Single quotes instead of double quotes

Symptom: "Unexpected token '".
Cause: JSON only allows double quotes. This is common when copying object literals out of JavaScript or Python.

// broken
{ 'name': 'Ada' }
// fixed
{ "name": "Ada" }

3. Missing quotes around keys

Cause: unquoted keys are valid JavaScript but invalid JSON.

// broken
{ name: "Ada" }
// fixed
{ "name": "Ada" }

4. Unexpected end of input

Cause: a missing closing brace }, bracket ], or quote. The parser reaches the end of the text while still expecting more. Count your opening and closing brackets — they must balance. The tree view in JSON Wallet makes unbalanced structures obvious because the offending branch will not render.

// broken - missing closing brace
{ "a": 1, "b": 2
// fixed
{ "a": 1, "b": 2 }

5. Unescaped characters in a string

Cause: a literal double quote, backslash, or newline inside a string without being escaped.

// broken
{ "msg": "She said "hi"" }
// fixed
{ "msg": "She said \"hi\"" }

A close cousin is the unescaped backslash, common in Windows file paths. Each backslash in the actual value needs to be doubled in JSON.

// broken
{ "path": "C:\Users\Ada" }
// fixed
{ "path": "C:\\Users\\Ada" }

6. Comments in JSON

Cause: JSON does not support // or /* */comments. They must be removed (or you need a superset like JSONC, which standard parsers will still reject). If you need to keep a note, move it into a string field.

7. Wrong value types

Cause: using undefined, NaN, Infinity, hex numbers, or numbers with leading zeros. Replace undefined with null, and write numbers in plain decimal.

// broken
{ "count": NaN, "id": undefined, "hex": 0xFF }
// fixed
{ "count": 0, "id": null, "hex": 255 }

8. A leading BOM or hidden characters

Cause: some editors save files with an invisible byte-order mark (BOM) or smart quotes (“ ”) pasted from a word processor. These look fine to the eye but break the parser. Re-typing the quotes or saving as plain UTF-8 usually fixes it.

9. Double-encoded (stringified) JSON

Symptom: after parsing, you get a string instead of an object.
Cause: the JSON was stringified twice, so the whole document is wrapped in quotes with every inner quote escaped. You need to parse it twice, or unstringify it once first.

// double-encoded (a string, not an object)
"{\"name\":\"Ada\"}"
// after one unstringify
{ "name": "Ada" }

See escaping and stringifying JSON for a full explanation of this very common confusion.

10. Numbers losing precision

Symptom: a large ID like 9007199254740993 comes back as 9007199254740992.
Cause: JSON numbers are double-precision floats and cannot represent every integer beyond 2^53. The fix is to send large identifiers as strings.

The fast way to find the problem

Reading JSON by eye is error-prone. Instead, paste it into JSON Wallet: the live validator pinpoints the exact line and column of the first error, and the Repair tool can automatically fix trailing commas, single quotes, missing quotes and unescaped characters in one click.

Frequently asked questions

What does "Unexpected token o in JSON at position 1" mean?

It usually means you called JSON.parse() on something that is already a JavaScript object (the "o" comes from the word object). Remove the extra parse, or check that you are parsing the raw response text, not an object.

Why is my valid-looking JSON still failing?

The usual culprits are invisible: a trailing comma, a smart quote, a BOM, or a stray control character. Paste the text into the editor — it will point to the precise character that breaks parsing.

Can I automatically fix broken JSON?

Many common errors (trailing commas, single quotes, missing quotes, unescaped characters) can be repaired automatically. Use the Repair button in JSON Wallet, then review the result — automated repair is a starting point, not a guarantee of correct intent.

For the underlying rules behind these errors, see JSON syntax rules explained.


Keep reading

Ready to put this into practice? Open the free JSON editor →