errorJSON Error Reference
Very Common

JSON Error: Unexpected Token

SyntaxError: Unexpected token X in JSON at position Y

What Causes This Error?

The "Unexpected token" error means the JSON parser encountered a character it didn't expect at a specific position in the string. It usually appears as "Unexpected token ," (trailing comma), "Unexpected token '" (single quote), or "Unexpected token n" (unquoted key starting with "n"). The position number in the error message points to the character that caused the problem.

Common Causes

  • arrow_rightA trailing comma after the last key-value pair in an object or array
  • arrow_rightSingle quotes used instead of double quotes for strings or keys
  • arrow_rightAn unquoted object key (valid in JavaScript, invalid in JSON)
  • arrow_rightA comment (// or /* */) inside the JSON
  • arrow_rightA JavaScript value like undefined or NaN where a JSON value is expected

Example: Broken vs Fixed JSON

cancel Invalid JSON (causes the error)

{
  "name": "Alice",
  "age": 30,
  "active": true,
}

check_circle Fixed JSON (valid)

{
  "name": "Alice",
  "age": 30,
  "active": true
}

Step-by-Step Fix Guide

1

Read the position number

The error says "at position Y". Count to that character in your JSON — that's where the parser failed. The actual mistake is usually one or two characters before that position.

2

Look for a trailing comma

Check the item just before every closing } or ] bracket. If there's a comma there, remove it. This is the most common cause of Unexpected token errors.

3

Check for single quotes

JSON requires double quotes for all strings and keys. Replace every single quote used as a string delimiter with a double quote.

4

Check for unquoted keys

Every JSON object key must be in double quotes. If you copied from a JavaScript object literal, wrap all keys in double quotes.

5

Re-validate

Paste the fixed JSON into the JSON Validator to confirm the error is gone before using it in your code.

Fix This Error Instantly

Paste your JSON into the validator to get the exact line number and error description. Then use the JSON Editor to make the fix and re-validate in one workflow.

Related JSON Errors

Fix JSON Unexpected Token Error – Causes & Solutions