How to Fix "Unexpected Token" Error in JSON

Published April 2025 · 5 min read

The Unexpected token error is the most common JSON parsing error. It means your JSON has a syntax mistake that the parser can't understand. Here's every cause and how to fix it.

1. Trailing Commas

JSON does NOT allow trailing commas. This is the #1 cause.

// ❌ WRONG
{"name": "John", "age": 30,}

// ✅ CORRECT
{"name": "John", "age": 30}

2. Single Quotes Instead of Double Quotes

JSON requires double quotes. Single quotes are invalid.

// ❌ WRONG
{'name': 'John'}

// ✅ CORRECT
{"name": "John"}

3. Comments in JSON

JSON does NOT support comments. Remove all // and /* */ comments.

// ❌ WRONG
{
  "name": "John" // user name
}

// ✅ CORRECT
{
  "name": "John"
}

4. Unquoted Keys

// ❌ WRONG
{name: "John"}

// ✅ CORRECT
{"name": "John"}

5. Unescaped Special Characters

Backslashes, newlines, and tabs inside strings must be escaped.

// ❌ WRONG
{"path": "C:\new\folder"}

// ✅ CORRECT
{"path": "C:\\new\\folder"}

6. Missing Commas Between Properties

// ❌ WRONG
{"name": "John" "age": 30}

// ✅ CORRECT
{"name": "John", "age": 30}

7. Using undefined or NaN

JSON only supports null, not undefined, NaN, or Infinity.

Quick Fix: Use Our JSON Validator

Paste your JSON into our JSON Formatter & Validator — it will tell you exactly where the error is and what's wrong.

Common Error Messages Explained

  • Unexpected token ' in JSON at position 0 — You're using single quotes
  • Unexpected token } in JSON — Trailing comma before closing brace
  • Unexpected token / in JSON — You have comments in your JSON
  • Unexpected end of JSON input — JSON is incomplete or truncated

Related Tools