Common JSON Parse Errors and How to Fix Them
JSON parse errors can be cryptic. This guide covers every common error message with the exact cause and fix for each one.
SyntaxError: Unexpected token
The most common JSON error. It means the parser encountered a character it didn't expect at that position. The character after "Unexpected token" tells you what was wrong.
❌ Unexpected token ' in JSON at position 1
Cause: Single quotes used instead of double quotes
Wrong: {'name': 'James'}Fix: {"name": "James"}❌ Unexpected token u in JSON at position 0
Cause: Variable is undefined — no JSON was returned
Wrong: JSON.parse(undefined)
Fix: if (response) JSON.parse(response)
❌ Unexpected token < in JSON at position 0
Cause: Server returned HTML instead of JSON (error page)
Wrong: <!DOCTYPE html><html>...
Fix: Check response.ok before calling response.json()
❌ Unexpected token , in JSON at position 45
Cause: Trailing comma after last item
Wrong: {"name": "James","age": 30,}Fix: {"name": "James","age": 30}SyntaxError: Unexpected end of JSON input
This error means the JSON string ended before the structure was complete. Usually caused by truncated responses or unclosed brackets.
// Truncated JSON — missing closing brackets
{"users": [
{"id": 1, "name": "James"},
{"id": 2, "name": "Anna" ← missing ] and }
// Fix — ensure your API returns complete responses
// Check timeout settings
// Check maximum response size settingsJSON parse errors by language
JavaScript
try {
const data = JSON.parse(jsonString)
} catch (e) {
if (e instanceof SyntaxError) {
console.error('JSON parse failed:', e.message)
// Log the problematic string
console.error('Input was:', jsonString?.substring(0, 100))
}
}Python
import json
try:
data = json.loads(json_string)
except json.JSONDecodeError as e:
print(f"JSON error: {e.msg}")
print(f"Line: {e.lineno}, Column: {e.colno}")
print(f"Position: {e.pos}")Java
try {
JsonNode node = objectMapper.readTree(jsonString);
} catch (JsonProcessingException e) {
System.err.println("JSON error: " + e.getMessage());
System.err.println("Location: " + e.getLocation());
}Fix JSON errors instantly
Our JSON formatter identifies the exact error location and auto-fixes the most common JSON mistakes.
Open JSON Formatter →