7 Common JSON Errors and How to Fix Them
JSON looks simple until it breaks your entire pipeline. Here are the 7 mistakes developers hit most often — with exact fixes you can apply in seconds.
If you have ever tried to parse a JSON file and been greeted by a cryptic error like Unexpected token < in JSON at position 0, you are not alone. JSON (JavaScript Object Notation) has strict syntax rules, and even a single misplaced character can break everything.
In this guide, we will walk through the 7 most common JSON errors, explain why each one happens, and show you how to fix them instantly. If you just want to paste your JSON and fix it right now, try our free JSON Formatter.
1. “Unexpected Token” at Position 0
This is the most googled JSON error. The message SyntaxError: Unexpected token < in JSON at position 0 almost always means you are not receiving JSON at all. Instead, your API or server is returning HTML — often a 404 page or a redirect.
Why it happens
- closeThe API endpoint URL is wrong (typo, missing path segment).
- closeThe server returns an HTML error page instead of JSON.
- closeA proxy or CDN is intercepting the request.
- closeYou called
response.json()on a non-JSON response.
How to fix it
fetch("/api/data")
.then(res => res.json()) // Server returned HTML!
.catch(err => console.error(err));fetch("/api/data")
.then(res => {
const contentType = res.headers.get("content-type");
if (!contentType?.includes("application/json")) {
throw new Error(`Expected JSON, got ${contentType}`);
}
return res.json();
})
.then(data => console.log(data))
.catch(err => console.error(err));Quick fix: Log the raw response text with res.text() first. If you see HTML (starts with <!DOCTYPE or <html), the problem is your URL or server config — not your JSON.
Paste your response into our JSON Formatter
It will tell you exactly what's wrong and where the syntax breaks.
2. Trailing Comma After the Last Item
JavaScript allows trailing commas in objects and arrays. JSON does not. This is one of the most frequent mistakes when hand-editing JSON.
{
"name": "Alice",
"age": 30,
}{
"name": "Alice",
"age": 30
}The fix is simple: remove the comma after the last property or array element. Tools like our JSON Formatter will highlight the exact line where the trailing comma appears.
3. Single Quotes Instead of Double Quotes
JSON requires double quotes around all strings and property keys. Single quotes are valid in JavaScript and Python, but they will cause a parse error in JSON.
{
'name': 'Alice',
'city': 'New York'
}{
"name": "Alice",
"city": "New York"
}Tip: If you are converting a Python dictionary to JSON, use json.dumps() instead of str(). The str() function will produce single-quoted output.
4. Unquoted Property Keys
In JavaScript, object keys do not need quotes. In JSON, every key must be a double-quoted string.
{
name: "Alice",
age: 30
}{
"name": "Alice",
"age": 30
}5. Missing Comma Between Items
Forgetting a comma between properties or array elements produces an “unexpected token” error at the position of the next key or value.
{
"name": "Alice"
"age": 30
}{
"name": "Alice",
"age": 30
}This error is easy to miss in large files. Our JSON Formatterpinpoints the exact line number so you don't have to hunt for it manually.
If you need to compare two versions of a JSON file to find what changed, use our Text Compare tool to highlight differences side by side.
7. Unescaped Special Characters in Strings
Certain characters inside JSON strings must be escaped with a backslash. The most common offenders:
| Character | Escape Sequence |
|---|---|
| " | \" |
| \ | \\ |
| Newline | \n |
| Tab | \t |
| Backspace | \b |
{
"path": "C:\Users\file.txt",
"message": "She said "hello""
}{
"path": "C:\\Users\\file.txt",
"message": "She said \"hello\""
}Quick Reference: JSON Error Cheat Sheet
| Error | Fix |
|---|---|
| Unexpected token at position 0 | Check the URL / response content type |
| Trailing comma | Remove the comma after the last item |
| Single quotes | Replace with double quotes |
| Unquoted keys | Wrap all keys in double quotes |
| Missing comma | Add commas between items |
| Comments in JSON | Remove comments or switch to JSONC/YAML |
| Unescaped characters | Escape with backslash |
Fix Your JSON Right Now
Stop guessing where the error is. Paste your JSON into one of these free tools and get instant results:
6. Comments in JSON
JSON does not support comments. No
//single-line, no/* */block comments. Adding them will break parsing immediately.Alternative: If you need comments in config files, consider using JSONC (JSON with Comments — used by VS Code), JSON5, or YAML. You can convert between YAML and JSON with our YAML to JSON converter.