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

May 22, 2026
JSONPath Guide: Query JSON Data Like SQL (with Examples)
Learn JSONPath syntax to query JSON data — basic expressions, wildcards, filters, recursive descent, and array slices. Includes JavaScript and Python examples.

May 22, 2026
How to Convert JSON to TypeScript Interfaces Automatically
Learn how to convert JSON to TypeScript interfaces — manually, with tools, and with AI. Includes nested objects, arrays, optional fields, and Zod schema generation.

May 22, 2026
JSON Schema Validation: A Complete Guide with Examples
Learn JSON Schema validation from scratch — Draft 7 syntax, required fields, type constraints, pattern matching, array validation, and validation with AJV in JavaScript.