Home/Blog/Fix Invalid JSON
TroubleshootingJune 10, 2026·6 min read

How to Fix Invalid JSON

Identify the error, understand why it happens, and fix it in seconds.

Why JSON Validation Fails

JSON is a strict format. Unlike JavaScript, it has no tolerance for trailing commas, comments, or single-quoted strings. A single misplaced character is enough to make the entire document invalid. The good news is that most errors fall into a small set of predictable patterns — and all of them can be fixed quickly once you know what to look for.

If you want to skip straight to fixing, paste your JSON into the JSON Fixer and it will repair the most common errors automatically.

1. Trailing Commas

The most common error. JSON does not allow a comma after the last item in an object or array.

// ❌ Invalid — trailing comma after "blue"
{
  "colors": ["red", "green", "blue",]
}

// ✅ Valid
{
  "colors": ["red", "green", "blue"]
}

This mistake is so common because JavaScript does allow trailing commas. Copying object literals from JS code directly into JSON files triggers this error regularly.

How to fix it: Remove the final comma before the closing ] or }. The JSON Fixer removes trailing commas automatically.

2. Single Quotes Instead of Double Quotes

JSON requires double quotes for both keys and string values. Single quotes are invalid even though they work in JavaScript.

// ❌ Invalid — single quotes
{
  'name': 'Alice',
  'role': 'admin'
}

// ✅ Valid
{
  "name": "Alice",
  "role": "admin"
}

How to fix it: Replace all single quotes with double quotes. The JSON Fixer handles this conversion automatically.

3. Unquoted Property Keys

All object keys in JSON must be wrapped in double quotes. JavaScript allows bare (unquoted) keys, but JSON does not.

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

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

How to fix it: Add double quotes around every key. The JSON Fixer does this automatically.

4. Comments

JSON has no comment syntax. Any // or /* */ blocks make the document invalid.

// ❌ Invalid — comments not allowed
{
  // User record
  "name": "Alice",
  "age": 30 /* verified */
}

How to fix it: Remove all comments. If you need annotations, add a dedicated "_comment" field or switch to JSONC (JSON with Comments) in your editor config.

5. Wrong Casing for Booleans and Null

JSON keywords are case-sensitive: true, false, and null must be lowercase. Python-style True, False, and None are invalid.

// ❌ Invalid — wrong casing
{
  "active": True,
  "deleted": False,
  "middleName": None
}

// ✅ Valid
{
  "active": true,
  "deleted": false,
  "middleName": null
}

This typically happens when serialising Python objects to JSON manually instead of using json.dumps().

6. Missing or Extra Brackets

Every { must have a matching }, and every [ must have a matching ]. Forgetting one — especially in deeply nested structures — is easy to do.

// ❌ Invalid — missing closing brace
{
  "user": {
    "name": "Alice"
}

// ✅ Valid
{
  "user": {
    "name": "Alice"
  }
}

How to fix it: The JSON Formatter highlights the exact line where the mismatch occurs. Fold the JSON in the editor to find which block is not closed.

7. Missing Commas Between Elements

Properties in an object and elements in an array must be separated by commas. Forgetting one is a common copy-paste mistake.

// ❌ Invalid — missing comma between properties
{
  "name": "Alice"
  "age": 30
}

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

8. Invalid Escape Sequences

Characters like ", \, and control characters inside strings must be escaped with a backslash. An unescaped quote inside a string ends the string prematurely, causing a parse error.

// ❌ Invalid — unescaped quote
{
  "message": "She said "hello""
}

// ✅ Valid
{
  "message": "She said \"hello\""
}

Using the JSON Fixer

The JSON Fixer repairs most of the errors above in one click:

  1. Paste your broken JSON into the left panel.
  2. The fixer automatically detects and repairs trailing commas, single quotes, unquoted keys, and Python-style booleans.
  3. Review the list of fixes applied on the right.
  4. Copy the repaired JSON to your clipboard.

For errors the fixer cannot repair automatically (like missing brackets or corrupted structure), the JSON Formatter will highlight the exact line so you can correct it manually.

Tips for Avoiding JSON Errors in the Future

  • Always use a code editor with JSON syntax highlighting (VS Code, Sublime Text, etc.)
  • Use a linter like ESLint with jsonc-eslint-parser for JSON files in your project
  • When serialising from code, use the language's built-in JSON serialiser (JSON.stringify in JS, json.dumps in Python) instead of building JSON strings manually
  • Validate API responses with the JSON Formatter before committing them as test fixtures

Related Tools

  • JSON Fixer — Automatically repair the most common JSON errors.
  • JSON Formatter — Validate and beautify JSON with error highlighting.
  • Common JSON Errors — A reference guide to all common JSON syntax mistakes.