How to Check If Your JSON Is Valid Online (and Fix It)

JSON fails silently in the worst places — a config that won't load, an API response that breaks your parser, a data file that throws an exception at runtime. Here's how to find the exact error and fix it in seconds.

Published March 28, 2026 · 6 min read

Why JSON Goes Invalid

JSON has strict syntax rules. Unlike JavaScript — where trailing commas, single quotes, and unquoted keys are all valid — JSON enforces a narrow spec. A single misplaced comma causes the entire document to fail to parse. The five most common causes, in order of frequency:

1. Trailing Commas

The most frequent mistake, especially when hand-editing JSON or copying from JavaScript code:

// INVALID — trailing comma after last item
{
  "name": "Alice",
  "age": 30,  ← this comma is illegal
}

// VALID
{
  "name": "Alice",
  "age": 30
}

JavaScript allows trailing commas in objects and arrays (since ES5). JSON does not. When you copy a JS object literal into a JSON file, trailing commas will break it.

2. Single-Quoted Strings

JSON requires double quotes. Single quotes produce a parse error:

// INVALID
{ 'name': 'Alice' }

// VALID  
{ "name": "Alice" }

3. Unquoted Keys

Object keys must be strings wrapped in double quotes. Unquoted keys are valid JavaScript but invalid JSON:

// INVALID
{ name: "Alice" }

// VALID
{ "name": "Alice" }

4. Missing Commas Between Items

Every item in an array or object (except the last) needs a comma after it. Missing a comma is an easy oversight when adding new fields:

// INVALID — missing comma between items
{
  "a": 1
  "b": 2
}

// VALID
{
  "a": 1,
  "b": 2
}

5. Comments

JSON does not support comments — neither // nor /* */. This surprises many developers coming from YAML or JSONC:

// INVALID
{
  // user data
  "name": "Alice"
}

// Strip comments before parsing, or use JSONC format

How to Validate JSON in Seconds

Paste your JSON into ToolLance's JSON Formatter and click "Validate." The validator runs JSON.parse() and reports the exact character position of any error. For example:

"Invalid JSON — SyntaxError: Expected ',' or '}}' after property value in JSON at position 47"

That position number is the character index of the failure. Count forward from the start of your JSON and you'll find the exact mistake.

Auto-Repair: Fix Without Counting Characters

If your JSON has any of the first three errors (trailing commas, single quotes, or unquoted keys), the JSON Formatter's Repair button fixes them automatically. Click "Repair" and the tool applies these transformations:

  • Removes trailing commas before } and ]
  • Converts single-quoted strings to double-quoted
  • Wraps unquoted keys in double quotes

The repaired JSON appears in the output panel, already formatted. If the repair still produces invalid JSON (e.g. because there are nested structural problems), the error message updates to show what remains.

Beyond Validation: What Else Can You Do

The JSON Formatter goes beyond basic validation:

  • Format/Beautify — Add consistent indentation (2 spaces, 4 spaces, or tabs) to make minified JSON readable
  • Minify — Strip all whitespace for compact production output
  • Sort Keys — Alphabetically sort all object keys recursively, making version-controlled JSON easier to diff
  • Tree View — Explore nested JSON as a collapsible interactive tree
  • Diff — Compare two JSON documents side-by-side to see exactly what changed between versions

Everything runs in your browser — nothing is uploaded, nothing is logged. If your JSON contains API keys, tokens, or personal data, it stays on your device.

Frequently Asked Questions

What makes JSON invalid?

The five most common causes: trailing commas, single-quoted strings, unquoted object keys, missing commas between items, and comments. JSON has stricter rules than JavaScript.

How do I fix a trailing comma in JSON?

Remove the comma after the last item in the object or array. Or click "Repair" in ToolLance's JSON Formatter — it fixes trailing commas automatically.

Can JSON have comments?

No. Standard JSON does not support // or /* */ comments. Use JSONC format (supported by VS Code) if you need comments, or strip them before parsing.

Is JSON case-sensitive?

Yes. JSON keys are case-sensitive — "Name" and "name" are different keys. The boolean values true, false, and null must be lowercase.