JSON Error: Unexpected Token
SyntaxError: Unexpected token X in JSON at position YWhat 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
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.
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.
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.
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.
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
Part of the JSON Toolkit
Explore All JSON Tools
Free online tools for every JSON task — format, validate, convert, compare, and more.