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.
Shashank Jain
Author


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
| Feature | Valid in JSON? | Fix |
|---|---|---|
| Trailing comma | No | Remove it |
| Single quotes | No | Use double quotes |
| Comments | No | Remove comments |
| undefined | No | Use null |
| NaN / Infinity | No | Use null |
Keep reading
Recent blogs

Jun 14, 2026
JSON in C#: System.Text.Json and Newtonsoft Complete Guide
Serialize and deserialize JSON in C# using System.Text.Json and Newtonsoft.Json with practical examples.

Jun 14, 2026
JSON to Markdown Table: Convert JSON Arrays Instantly
Convert JSON arrays to Markdown tables in JavaScript, Python, and with the free online tool.

Jun 14, 2026
JSON in TypeScript: Type-Safe Parsing and Validation
Stop using any for JSON in TypeScript — use Zod, type guards, and generics for fully type-safe parsing.