JSON Validation Errors: 7 Most Common and How to Fix Them

·7 min read

Introduction

A reliable JSON validator online is every developer's first line of defence against malformed data. This guide walks through the 7 most common JSON validation errors — with real broken JSON examples and exactly how to fix each one.

1. Trailing Commas

What causes it: A comma after the last element in an array or the last key-value pair in an object. This is valid in JavaScript objects and many other languages, so developers frequently write it by habit.

// ❌ INVALID
{
  "name": "Alice",
  "age": 30,
}
// ✅ FIXED
{
  "name": "Alice",
  "age": 30
}

Fix: Remove the comma after the last item. A JSON validator will show the exact line where this occurs.

2. Single-Quoted Strings

What causes it: JSON requires double quotes for all strings — both keys and values. Single quotes are valid in JavaScript but invalid in JSON.

// ❌ INVALID
{'name': 'Alice'}
// ✅ FIXED
{"name": "Alice"}

Fix: Replace all single quotes with double quotes. Use Find & Replace in your editor.

3. Unquoted Keys

What causes it: JavaScript allows unquoted object keys, but JSON does not. Every key must be a double-quoted string.

// ❌ INVALID
{name: "Alice", age: 30}
// ✅ FIXED
{"name": "Alice", "age": 30}

4. Missing Commas Between Key-Value Pairs

What causes it: Each key-value pair in an object must be separated by a comma. Missing commas are common when manually editing JSON.

// ❌ INVALID
{
  "name": "Alice"
  "age": 30
}
// ✅ FIXED
{
  "name": "Alice",
  "age": 30
}

5. Mismatched Brackets or Braces

What causes it: Every { must have a matching }, and every [ must have a matching ]. This is easy to miss in large deeply-nested JSON.

// ❌ INVALID
{"users": [{"name": "Alice"}
// ✅ FIXED
{"users": [{"name": "Alice"}]}

Fix: Use a JSON formatter with bracket matching to identify which bracket is unclosed.

6. Comments in JSON

What causes it: Developers familiar with JSONC (JSON with Comments) add // or /* */ comments. These are not valid in standard JSON.

// ❌ INVALID
{
  // user data
  "name": "Alice"
}
// ✅ FIXED
{
  "name": "Alice"
}

Fix: Strip all comments before parsing or validating. If you need comments in config files, consider HJSON or TOML instead.

7. Invalid Values (undefined, NaN, Infinity)

What causes it: JSON only supports null, not JavaScript's undefined, NaN, or Infinity. These appear when serialising JavaScript objects with JSON.stringify() without handling edge cases.

// ❌ INVALID
{"score": NaN, "ratio": Infinity}
// ✅ FIXED
{"score": null, "ratio": null}

Fix: Replace NaN and Infinity with null or a sentinel numeric value before serialising.

Catch All These Errors Instantly

Instead of hunting through JSON manually, use our JSON Validator Online to detect all of these errors automatically. Paste your JSON and get the exact line number of every error in under a second.