JSON Unexpected Token
Learn what causes the 'JSON Parse error: Unexpected token' error and how to fix it in JavaScript, Python, and other languages.
What Does This Error Mean?
The 'Unexpected token' error occurs when JSON.parse() or equivalent encounters a character it does not expect at the current position in the input string. This typically means the JSON is malformed — it contains invalid syntax that does not conform to the JSON specification.
Common Causes
Trailing comma after the last element in an object or array
Single quotes used instead of double quotes for strings
Missing closing brace, bracket, or quote
BOM (Byte Order Mark) character at the start of the file
Comments embedded in JSON (not allowed per spec)
Control characters or invisible Unicode in string values
How to Fix It
Validate your JSON
Paste your JSON into a JSON validator to find the exact syntax error location. Most validators highlight the problematic character and line number.
// Use a JSON validator JSON.parse(yourString); // throws SyntaxError: Unexpected token
Remove trailing commas
JSON does not allow trailing commas. Remove the comma after the last property in an object or the last element in an array.
// ❌ Invalid: trailing comma
{ "name": "John", "age": 30, }
// ✅ Valid
{ "name": "John", "age": 30 }Use double quotes
JSON requires double quotes for all strings, including property names. Single quotes are not valid.
// ❌ Invalid: single quotes
{ 'name': 'John' }
// ✅ Valid
{ "name": "John" }Strip BOM characters
If your JSON was edited with Windows Notepad or certain editors, it may have a BOM character. Strip it before parsing.
// Remove BOM from JSON string
function stripBOM(str) {
if (str.charCodeAt(0) === 0xFEFF) return str.slice(1)
return str
}Before & After Examples
{ "users": [{ "id": 1 }, { "id": 2 },] }{ "users": [{ "id": 1 }, { "id": 2 }] }{ 'name': 'John', 'age': 30 }{ "name": "John", "age": 30 }Related Tools
Use these tools to debug and fix this error:
Related Guides
Deepen your understanding with these guides and tutorials:
Related Errors
Other common errors in this category:
JSON Unexpected End of Input
Learn why 'Unexpected end of JSON input' occurs and how to fix truncated or incomplete JSON data.
JSON Circular Reference Error
Fix 'Converting circular structure to JSON' error when using JSON.stringify with objects that reference themselves.
JSON BigInt Truncation Error
Fix JSON BigInt truncation when JSON.parse loses precision with large integers. Learn how to handle BigInt values in JSON.
Frequently Asked Questions
Why does my JSON work in one language but not another?
Some languages have more lenient JSON parsers. For example, JavaScript's eval() can parse single quotes and trailing commas, but JSON.parse() strictly follows the JSON specification.
Can I use comments in JSON?
No. JSON does not support comments by specification. Use JSONC (JSON with Comments) if your parser supports it, or strip comments with a preprocessing step.
What is 'Unexpected token < in JSON at position 0'?
This typically means you're trying to parse an HTML response as JSON. You likely have a server error page or a 404 HTML page being returned where you expected a JSON response.