Fix "Unexpected Token" Error in JSON
Learn what causes the Unexpected Token error in JSON and fix it instantly. Interactive examples, plain-English explanations, and AI-powered repair.
Try it — click an error to see the fix:
{
"name": "Alice",
"age": 30,
}Cause: Comma after the last property before }Click an error above to see the fix →
What Causes "Unexpected Token" in JSON?
The "Unexpected token" error occurs when JSON.parse() encounters a character that violates the JSON specification. JSON is stricter than JavaScript — it does not allow trailing commas, single quotes, comments, unquoted keys, or values like undefined and NaN. When any of these appear in your data, the parser stops and reports the position of the unexpected character.
This is the single most common JSON error developers encounter. It typically happens when copying data from JavaScript source code, Python dictionaries, API logs, or config files that use a relaxed JSON variant (JSONC). The fix is usually simple — but finding the exact character can be tedious without the right tool.
6 Most Common Causes (With Examples)
1. Trailing Commas
The comma after 30 is invalid. JSON does not allow a comma before the closing } or ]. This is the #1 cause of unexpected token errors.
{ "name": "Alice", "age": 30, }{ "name": "Alice", "age": 30 }2. Single Quotes Instead of Double Quotes
JSON requires double quotes (") for all strings and keys. Single quotes (') are valid in JavaScript and Python but not in JSON.
{ 'name': 'Alice' }{ "name": "Alice" }3. Unquoted Object Keys
In JavaScript, object keys can be unquoted. In JSON, every key must be a double-quoted string.
{ name: "Alice" }{ "name": "Alice" }4. Comments (// or /* */)
JSON does not support any form of comments. This catches developers who work with JSONC (JSON with Comments) in VS Code configs.
{ "name": "Alice" // user name
}{ "name": "Alice" }5. undefined, NaN, or Infinity
These JavaScript-specific values have no JSON equivalent. Use null for missing values and regular numbers for NaN/Infinity.
{ "value": undefined }{ "value": null }6. HTML Instead of JSON (Unexpected token <)
When you see "Unexpected token <", it means an API returned HTML (like an error page) instead of JSON. Check your URL and authentication.
<html><body>404 Not Found</body></html>
{ "error": "Not Found", "status": 404 }How to Fix "Unexpected Token" Errors
Find the Error Location
The error message includes a position (e.g., "at position 42"). Use our JSON Validator to see the exact line and column highlighted in the editor.
Check the Character Before the Position
The actual problem is usually one character before where the parser reports the error. Look for trailing commas, single quotes, or comments near that position.
Fix Automatically
Paste your broken JSON into our Fix JSON Error tool. It detects and fixes all common causes instantly — trailing commas, single quotes, unquoted keys, comments, and invalid values.
Still stuck? Let AI fix it for you.
Paste your broken JSON into our AI-powered fixer. It handles complex structural issues that go beyond simple syntax — and explains every fix in plain English.
Fix JSON Errors with AIRelated Tools
Fix JSON Errors
AI-powered JSON repair with plain-English explanations
JSON Validator
Check JSON syntax with exact error location
JSON Formatter
Prettify and minify valid JSON
JSON Repair Tool
Quick regex-based repair for common issues
JSON Tree Viewer
Visualize JSON as a collapsible tree
JSON Diff Checker
Compare original vs fixed JSON
Frequently Asked Questions
It means the JSON parser encountered a character it was not expecting at a specific position. The parser reads JSON character by character, and when it finds something that does not follow the JSON specification (RFC 8259), it throws this error. The "token" is the unexpected character — it could be a comma, quote, letter, or bracket.
The most common causes are: trailing commas after the last property ({"a": 1,}), single quotes instead of double quotes ({'a': 1}), unquoted object keys ({a: 1}), JavaScript comments (// or /* */), and using undefined, NaN, or Infinity as values. All of these are valid in JavaScript but not in JSON.
The error message usually includes a position number (e.g., "at position 42") or line and column (e.g., "line 3 column 5"). Use our JSON Validator to highlight the exact error location in the editor, or paste your JSON into the Fix JSON Error tool for automatic detection and repair.
Yes. Our Fix JSON Error tool automatically detects and repairs the most common causes — trailing commas, single quotes, unquoted keys, comments, and invalid values like undefined. For complex structural issues, the AI-powered fixer can handle cases that regex cannot.
The JSON specification (RFC 8259) was designed as a strict data interchange format. Trailing commas were excluded to keep the grammar simple and unambiguous. JavaScript allows them, but JSON does not. This is the #1 cause of "Unexpected token" errors.
JSON requires all strings and keys to use double quotes ("). Single quotes (') are valid in JavaScript and Python, but not in JSON. This design choice ensures consistency and avoids ambiguity in parsing. If you have single-quoted JSON, our tool converts it to double quotes automatically.
Yes. In JavaScript, JSON.parse() throws a SyntaxError with the message "Unexpected token..." when it encounters invalid JSON. The full error is typically "SyntaxError: Unexpected token X in JSON at position Y". Other browsers may phrase it differently, but they all mean the same thing.
This specific error usually means you are trying to parse HTML instead of JSON. It happens when an API returns an HTML error page (like a 404 or 500 page) instead of a JSON response. Check your API URL, authentication, and response headers (Content-Type should be application/json).