🔧 Error: Unexpected Token in JSON
Learn why JavaScript throws "SyntaxError: Unexpected token" and how to debug and repair your JSON input.
The Error Signature
This error triggers when you pass a malformed string into JSON.parse(). Since JSON is a highly strict syntax standard, even a minor discrepancy will crash the parser.
SyntaxError: Unexpected token ' in JSON at position 12
at JSON.parse (<anonymous>)Common Causes & Code Examples
1. Single Quotes instead of Double Quotes
JSON does not allow single quotes for keys or string values.
{
'name': 'Developer',
"active": true,
}To fix, replace all single quotes with straight double quotes and remove any trailing commas:
{
"name": "Developer",
"active": true
}2. Unescaped Control Characters
Strings containing real tabs, raw carriage returns, or unescaped forward slashes will fail validation. Use \\n or \\t instead of raw tabs or line breaks inside string values.
3. Trailing Commas
Avoid placing commas after the final key-value pair of an object or the final item of an array list.
Resolution Checklist
- Identify the error position: Copy your JSON string into a text editor, search for the byte/character index indicated in the error message, and inspect that location.
- Validate online: Paste the text into our JSON Formatter tool to automatically highlight the exact line and character causing the syntax breakdown.
- Check smart quotes: Replace any curly quotes like
“or”with normal straight quotes".
Frequently Asked Questions
Resolve JSON.parse debugging blockers.