8 min read

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

✗ Wrong — parsing HTML as JSON
fetch("/api/data")
  .then(res => res.json()) // Server returned HTML!
  .catch(err => console.error(err));
✓ Fixed — check content type first
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.

code

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.

✗ Invalid JSON — trailing comma
{
  "name": "Alice",
  "age": 30,
}
✓ Valid JSON — no trailing comma
{
  "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.

✗ Invalid — single quotes
{
  'name': 'Alice',
  'city': 'New York'
}
✓ Valid — double quotes
{
  "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.

✗ Invalid — unquoted keys
{
  name: "Alice",
  age: 30
}
✓ Valid — quoted keys
{
  "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.

✗ Missing comma after 'name'
{
  "name": "Alice"
  "age": 30
}
✓ Fixed
{
  "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.

6. Comments in JSON

JSON does not support comments. No // single-line, no /* */ block comments. Adding them will break parsing immediately.

✗ Invalid — comments not allowed
{
  // This is a user object
  "name": "Alice",
  "age": 30 /* years old */
}
✓ Valid — remove all comments
{
  "name": "Alice",
  "age": 30
}

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.

7. Unescaped Special Characters in Strings

Certain characters inside JSON strings must be escaped with a backslash. The most common offenders:

CharacterEscape Sequence
"\"
\\\
Newline\n
Tab\t
Backspace\b
✗ Invalid — unescaped quote inside string
{
  "path": "C:\Users\file.txt",
  "message": "She said "hello""
}
✓ Valid — properly escaped
{
  "path": "C:\\Users\\file.txt",
  "message": "She said \"hello\""
}

Quick Reference: JSON Error Cheat Sheet

ErrorFix
Unexpected token at position 0Check the URL / response content type
Trailing commaRemove the comma after the last item
Single quotesReplace with double quotes
Unquoted keysWrap all keys in double quotes
Missing commaAdd commas between items
Comments in JSONRemove comments or switch to JSONC/YAML
Unescaped charactersEscape 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: