JSON Validator: How to Find and Fix Common JSON Errors

That cryptic "Unexpected token" error? Here's exactly what it means and how to fix it in 30 seconds.

🔍 Validate Your JSON Now

Paste broken JSON and get instant error detection with line numbers.

Open JSON Validator →

The Frustration of "Unexpected Token"

Every developer has seen it: SyntaxError: Unexpected token. You're trying to parse a JSON response, load a config file, or debug an API call, and suddenly everything breaks. The error message is almost useless — it tells you something is wrong but rarely tells you what.

The root cause is almost always one of six common mistakes. Once you know what to look for, you can fix any broken JSON in seconds. And with a proper JSON validator, you don't even need to look — the tool finds the error for you.

The 6 Most Common JSON Errors

1. Trailing Commas

This is the #1 JSON error. JavaScript and TypeScript allow trailing commas, so developers naturally write them in JSON too. But JSON strictly forbids them.

// ❌ Invalid — trailing comma after "editor"
{
  "name": "Alice",
  "roles": ["admin", "editor",],
  "active": true,
}

// ✅ Valid — no trailing commas
{
  "name": "Alice",
  "roles": ["admin", "editor"],
  "active": true
}

Fix: Remove the comma before any closing ] or }.

2. Single Quotes Instead of Double Quotes

Python developers hit this constantly. Python's json.dumps() outputs double quotes, but when you manually write JSON or copy from Python's repr(), you might use single quotes.

// ❌ Invalid
{'name': 'Alice', 'age': 30}

// ✅ Valid
{"name": "Alice", "age": 30}

Fix: Replace all single quotes with double quotes. A find-and-replace usually works, but be careful with values that contain apostrophes.

3. Unquoted Property Keys

In JavaScript objects, you can write {name: "Alice"}. In JSON, every key must be a double-quoted string.

// ❌ Invalid
{name: "Alice", age: 30}

// ✅ Valid
{"name": "Alice", "age": 30}

Fix: Wrap every key in double quotes.

4. Comments

JSON has no comment syntax. No //, no /* */, no #. This surprises many developers because it seems like such a basic feature.

// ❌ Invalid
{
  "database": "production",  // don't change this
  "port": 5432
}

// ✅ Valid
{
  "database": "production",
  "port": 5432
}

Fix: Remove all comments. If you need comments in config files, consider using JSONC, YAML, or TOML instead.

5. Missing Commas Between Elements

When you're editing JSON by hand — adding or removing fields — it's easy to forget a comma between key-value pairs or array elements.

// ❌ Invalid — missing comma after line 2
{
  "name": "Alice"
  "age": 30
}

// ✅ Valid
{
  "name": "Alice",
  "age": 30
}

Fix: Ensure every element except the last has a comma after it.

6. Incorrect Value Types

JSON supports strings, numbers, booleans (true/false), null, objects, and arrays. Common mistakes include using undefined, NaN, Infinity, or unquoted strings as values.

// ❌ Invalid
{"value": undefined, "count": NaN, "status": active}

// ✅ Valid
{"value": null, "count": 0, "status": "active"}

Fix: Use null instead of undefined, a number instead of NaN/Infinity, and quote all string values.

How to Debug JSON Efficiently

When you encounter a JSON parse error, follow this workflow:

  1. Paste into a validator: Use our JSON validator to get the exact error location with line and character numbers.
  2. Look at the error line: The problem is usually on or just before the reported line.
  3. Check the usual suspects: Trailing commas, single quotes, missing commas, comments.
  4. Format and inspect: Once fixed, format the JSON to visually verify the structure looks correct.
  5. Test round-trip: If you're working with a specific language, verify with JSON.parse() (JavaScript), json.loads() (Python), or your language's equivalent.

JSON Validation in Different Contexts

API Response Debugging

When an API returns unexpected data, copy the raw response and paste it into the validator. This immediately tells you whether the issue is malformed JSON or a logic error in your parsing code.

Configuration Files

JSON config files (like package.json, tsconfig.json, or custom app configs) are common sources of errors after manual editing. Always validate after editing these files by hand.

Data Migration

When converting data between formats (CSV to JSON, XML to JSON), validation catches encoding issues, escaped character problems, and structural errors in the output.

Beyond Syntax: Schema Validation

Syntax validation tells you if JSON is well-formed. But is it correct? JSON Schema lets you define the expected structure — required fields, data types, value ranges — and validate data against it. While our tool focuses on syntax validation, knowing about JSON Schema is valuable for production systems where you need to enforce data contracts.

Pro Tips for Avoiding JSON Errors

Fix Your JSON Now

Paste broken JSON, see the exact error, fix it in seconds.

Open JSON Validator →

Recommended Tools & Resources

Level up your workflow with these developer tools:

Try DigitalOcean → Try Neon Postgres → Clean Code by Robert C. Martin →

Dev Tools Digest

Get weekly developer tools, tips, and tutorials. Join our developer newsletter.

Frequently Asked Questions

Why is my JSON invalid?

Common causes: trailing commas after the last element, single quotes instead of double quotes, unquoted property keys, missing commas between elements, undefined or NaN values, and comments in the JSON.

How do I fix a JSON parsing error?

Paste your JSON into devtoolkit.cloud/tools/json-formatter — it highlights the exact line and position of syntax errors. Common fixes: replace single quotes with double, remove trailing commas, add missing commas, and quote all keys.

Can I use single quotes in JSON?

No. JSON strictly requires double quotes for both keys and string values. Single quotes will cause a parse error. If you're getting JSON from JavaScript, make sure to use JSON.stringify() which always outputs double quotes.