Skip to main content
JSON & Data
Published 8 min read

JSON Validator: How to Find and Fix Invalid JSON

A single misplaced comma breaks the whole document. Here's how validation finds it and what the common causes are.

"Invalid JSON" is a syntax judgment, not a data judgment - it means the text doesn't parse as valid JSON at all, regardless of whether the values inside would otherwise make sense. Validation is the process of running that check and, ideally, telling you exactly where it failed.

What validation checks

A validator attempts to parse the text according to the JSON grammar: matched braces and brackets, properly quoted strings, colons between keys and values, commas between items, and no trailing commas. If parsing succeeds, the JSON is valid - full stop. There's no partial validity.

The most common causes of invalid JSON

CauseExampleWhy it fails
Trailing comma{"a": 1, "b": 2,}JSON doesn't allow a comma after the last item
Single quotes{'a': 1}JSON requires double quotes for strings and keys
Unquoted keys{a: 1}Keys must be quoted strings
Missing comma{"a": 1 "b": 2}Items need a comma separator
Smart quotes{“a”: 1}Curly quotes from a word processor aren't valid JSON quotes
Comments{"a": 1 // note}Standard JSON has no comment syntax

Reading a validation error message

A good validator points to an exact line and column, plus a short description. For example:

Unexpected token , in JSON at position 42 (line 3, column 15)

The position tells you where the parser gave up - which is usually right at, or just after, the actual mistake. A trailing comma error, for instance, typically points to the character right before the closing brace or bracket.

A worked example

{
  "name": "Alice",
  "active": true,
}

This fails because of the trailing comma after true - there's no fourth item to separate. Removing that one comma makes it valid:

{
  "name": "Alice",
  "active": true
}

Why manual scanning gets slow

For a short object, spotting a stray comma or mismatched quote by eye is quick. For a real-world API response with dozens of nested fields, scanning line by line for one misplaced character is slow and genuinely easy to miss - which is exactly the case where a validator earns its keep by pointing directly at the problem.

The JSON Formatter validates automatically as you type, showing the exact line, column, and a plain-English description of the problem - along with one-click suggested fixes for the most common mistakes like trailing commas and unquoted keys.

Valid JSON vs. "JSON that makes sense"

A validator only checks syntax. {"age": "twelve"} is perfectly valid JSON even if your application expects age to be a number - that's a semantic/schema concern, which is a separate problem from syntactic validity and requires different tooling (like a JSON Schema validator) to catch.

Common mistakes

  • Assuming JSON copied from a formatted code block in a document is clean - word processors frequently substitute curly quotes for straight ones.
  • Missing a trailing comma introduced by an editor's auto-formatting when a field was deleted.
  • Trying to fix a validation error without reading the specific line/column the validator points to, and instead guessing at the whole document.

For a full breakdown of each mistake type with more examples, see Common JSON Syntax Errors and How to Fix Them.

Summary

JSON validation is a strict pass/fail parse check, and the value of a good validator is in exactly where it points when something fails - line, column, and a clear description, rather than just "invalid."

Frequently asked questions

How do I validate JSON?
Run it through a parser - if the parser succeeds, the JSON is syntactically valid. Most JSON tools report the specific line and column of the first error rather than just "invalid" if parsing fails.
Why does my JSON look correct but still fail validation?
The most common invisible culprits are a trailing comma after the last item, smart/curly quotes from a word processor instead of straight double quotes, or a stray character copied in from elsewhere.
Can JSON be valid but still wrong for my use case?
Yes - syntactic validity (correct JSON structure) is different from semantic correctness (the right fields with the right values for your application). A validator only checks the former.

The tool that pairs with this guide.

Did this help you untangle that JSON?

If these free developer tools save you time, consider buying me a byte. Your support helps keep DevCraftKit free and growing.

Buy me a byte 💾