Troubleshooting

10 Common JSON Syntax Errors and How to Fix Them Instantly

A troubleshooting guide covering the most frequent JSON parsing syntax errors, invalid escape sequences, and how to debug them in seconds.

## The Frustration of "Unexpected token in JSON" Almost every developer has stared down the dreaded: ``` SyntaxError: Unexpected token ' in JSON at position 12 ``` Because the JSON specification is rigid, even a single stray character or unquoted key causes the entire document parsing to fail. Here are the 10 most common JSON syntax mistakes and their solutions. --- ## Top 5 Culprits Behind JSON Parsing Failures ### 1. Single Quotes Instead of Double Quotes - ❌ `{'name': 'Alex'}` - ✅ `{"name": "Alex"}` - **Rule**: RFC 8259 strictly requires double quotes (`"`) for all object keys and string values. ### 2. Trailing Commas - ❌ `{"items": [1, 2, 3,] }` - ✅ `{"items": [1, 2, 3] }` - **Rule**: No commas after the final element in an array or property in an object. ### 3. Unquoted Keys - ❌ `{ active: true }` - ✅ `{ "active": true }` - **Rule**: Unlike JavaScript object literals, JSON keys must always be enclosed in double quotes. ### 4. JavaScript Comments Inside JSON - ❌ `// Server configuration\n{"port": 8080}` - ✅ `{"port": 8080}` - **Rule**: Standard JSON does not permit comments. If you need comments, consider JSONC (JSON with Comments) or YAML. ### 5. Unescaped Control Characters in Strings - ❌ `{"bio": "Line 1 \n Line 2"}` with unescaped literal raw newlines. - ✅ `{"bio": "Line 1 \n Line 2"}` with escaped `\n`. --- Diagnose your broken JSON strings instantly with line and character indicators on the [LABSTACK JSON Formatter](/tools/json-formatter).