How to fix common JSON errors

Most "Unexpected token …" and "JSON.parse" errors come from a handful of small syntax mistakes. Here's each one, why it breaks, and the fix. The fastest way to find yours: paste the JSON into the viewer — it points to the exact spot that fails.

Validate & fix my JSON →

1. Trailing comma

A comma after the last item is the single most common cause of Unexpected token } in JSON.

✗ {"a": 1, "b": 2,}
✓ {"a": 1, "b": 2}

2. Single quotes instead of double

JSON requires double quotes for both keys and string values. Single quotes give Unexpected token ' in JSON.

✗ {'name': 'Ada'}
✓ {"name": "Ada"}

3. Unquoted keys

Object keys must be quoted strings. {name: "Ada"} is valid JavaScript but invalid JSON.

✗ {name: "Ada"}
✓ {"name": "Ada"}

4. Comments

JSON does not allow // or /* */ comments. Remove them (or use JSON5 if your parser supports it).

✗ {"a": 1 // the first one}
✓ {"a": 1}

5. Missing comma between items

✗ {"a": 1 "b": 2}
✓ {"a": 1, "b": 2}

6. Unescaped characters in strings

Literal newlines, tabs, or unescaped double quotes inside a string are invalid. Escape them with a backslash.

✗ {"msg": "She said "hi""}
✓ {"msg": "She said \"hi\""}

7. Trailing or wrapping text

A JSON document must be a single value. A variable assignment, an anti-hijacking prefix like )]}',, or a stray character at the end all cause parse errors. Keep only the JSON itself.

✗ var data = {"a": 1};
✓ {"a": 1}

8. Invalid numbers and values

JSON has no NaN, Infinity, undefined, leading zeros (007), or trailing decimal points. Use a valid number, a quoted string, or null.

✗ {"x": NaN, "y": 007, "z": undefined}
✓ {"x": null, "y": 7, "z": null}

Find the exact error fast

Rather than hunting by eye, paste your JSON into the free JSON viewer: it validates as you paste, reports the first error, and renders the rest as a collapsible tree so you can see where the structure breaks — even for large files. Nothing is uploaded; it all runs in your browser.

Open the JSON viewer →