jsondecode.com logo

HomeChevronBlogChevronHow to Fix 'Unexpected Token' in JSON: Complete Guide (2026)

Blog post

How to Fix 'Unexpected Token' in JSON: Complete Guide (2026)

Learn what causes the 'Unexpected token' JSON error, see the 5 most common causes with before/after examples, and fix it instantly using a free online tool.

author

Shashank Jain

Author

22/05/20260 minutes 46 seconds read
How to Fix 'Unexpected Token' in JSON: Complete Guide (2026)How to Fix 'Unexpected Token' in JSON: Complete Guide (2026)

Article

What Is the 'Unexpected Token' Error in JSON?

The SyntaxError: Unexpected token error means the JSON parser encountered a character it did not expect. JSON has strict syntax rules defined in RFC 8259 — any deviation throws this error immediately.

5 Common Causes

1. Trailing Commas

The most frequent cause. JSON does not allow a comma after the last item in an array or object.

// INVALID
{"name": "Alice", "age": 30,}

// VALID
{"name": "Alice", "age": 30}

2. Single Quotes

JSON requires double quotes for all strings and keys. Single quotes are valid JavaScript but invalid JSON.

// INVALID
{'name': 'Alice'}

// VALID
{"name": "Alice"}

3. Unquoted Keys

// INVALID
{name: "Alice"}

// VALID
{"name": "Alice"}

4. Comments

JSON does not support // or /* */ comments. Remove them before parsing.

5. undefined, NaN, or Infinity

These JavaScript-only values are not valid in JSON. Replace with null or a number.

How to Fix It Fast

Paste your JSON into the JSON formatter at jsondecode.com — it highlights the exact error line and explains what went wrong.

Quick Reference Table

FeatureValid in JSON?Fix
Trailing commaNoRemove it
Single quotesNoUse double quotes
CommentsNoRemove comments
undefinedNoUse null
NaN / InfinityNoUse null

Keep reading

Recent blogs

View all

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.