What an Invalid JSON Error Actually Means
An invalid JSON error means the payload is not compliant with strict JSON syntax. Typical parser messages includeUnexpected token, Unexpected end of JSON input, and Expecting property name enclosed in double quotes. JSON parsers are strict by design: a single trailing comma or unescaped quote can break the entire payload.
Start with validation first, then formatting. Use JSON Validator to get line/column errors and JSON Formatter to make the structure readable.
Most Common JSON Parse Error Patterns
Unexpected token JSON
{"name": "Ava", age: 30}Problem: key age is unquoted.
Trailing comma
{
"name": "Ava",
"age": 30,
}Problem: trailing comma after last field.
Single quotes or unescaped content
{'name':'Ava'}Problem: JSON requires double quotes for keys and strings.
Unexpected token < in JSON
This usually means your endpoint returned HTML (often an error page or auth redirect) while your code expected JSON. Inspect the raw response body before parsing.
5-Minute Troubleshooting Workflow
- Copy raw payload (before any object mapping).
- Validate in JSON Validator.
- Fix exact line/column issue.
- Reformat in JSON Formatter.
- Compare old vs fixed payload in JSON Diff.
| Error message | Likely cause | Fix |
|---|---|---|
| Unexpected token } | Trailing comma | Remove final comma |
| Unexpected token < | HTML response, not JSON | Inspect response body and content type |
| Expecting property name | Unquoted key | Use double-quoted keys |
Language-Specific Examples
JavaScript
try {
const data = JSON.parse(raw);
} catch (err) {
console.error('JSON parse error:', err.message);
}Python
import json
try:
data = json.loads(raw)
except json.JSONDecodeError as e:
print(e.msg, e.lineno, e.colno)C#
using System.Text.Json;
try {
var doc = JsonDocument.Parse(raw);
} catch (JsonException ex) {
Console.WriteLine(ex.Message);
}Java
ObjectMapper mapper = new ObjectMapper();
try {
Object value = mapper.readValue(raw, Object.class);
} catch (Exception e) {
System.out.println(e.getMessage());
}Real Use Cases from Developer Teams
- API integration debugging: broken payloads between staging and production.
- Config deployments: malformed JSON in env-specific config files.
- ETL pipelines: partial records containing invalid escape characters.
- Webhook processing: unexpected HTML or text response from upstream systems.
Screenshot Recommendations
- Validator view showing line-numbered parse error.
- Before/after formatted payload screenshot.
- JSON Diff screenshot comparing failing and fixed payload.
Pro Tips
- Always log raw responses when parse fails.
- Validate first, map to domain models second.
- Treat "Unexpected token <" as a response-type bug, not JSON syntax bug.
- Use schema checks after syntax validation for robust pipelines.
FAQ
How do I fix invalid JSON quickly?
Paste into a validator, fix the exact line/column error, then re-run parse.
Why does JSON.parse fail while payload looks correct?
Often hidden issues: trailing commas, bad escaping, or non-JSON response content.
Can I validate large JSON online?
Yes. Use JSON Validator and then JSON Formatter for readable inspection.
Get Started with formatterjson.org
Validate malformed payloads with JSON Validator, format for readability with JSON Formatter, and compare payload versions with JSON Diff.