Developer

How to Format and Validate JSON (and Fix the Error Google Sends You)

A five-minute method for turning a wall of minified JSON into readable, valid data — plus the errors that break most files.

6 min readUpdated 2026-10-10

JSON is the least forgiving format in common use: one stray comma and the whole document is invalid. If you have ever pasted a payload into a validator and got a position number with no explanation, this is the workflow that fixes it in minutes.

Why “invalid JSON” happens

JSON’s rules are deliberately strict, and hand-editing breaks them in predictable ways: trailing commas (fine in JavaScript, illegal here), single quotes, comments, unquoted keys, and smart quotes pasted in from a document editor. None of those are cosmetic — each one makes the file unparseable.

The five-minute fix

  1. Paste it into the formatter The JSON Formatter validates as you paste and points at the failing line rather than an offset.
  2. Fix the reported error Work from the first error only — later ones are usually knock-on effects.
  3. Format with 2-space indentation Readable structure makes the next error obvious.
  4. Compare with the previous known-good version If you have a backup, JSON Diff Checker shows exactly which keys were added, removed or changed.
  5. Minify before shipping JSON Minifier strips the whitespace you added while reading — 30–60% smaller payloads are normal.

The errors that cause 90% of failures

What you wroteWhy it fails
{"a": 1,}Trailing comma — JSON has no trailing commas, ever
{a: 1}Keys must be double-quoted strings
{'a': 1}Single quotes are not JSON, use double quotes
// commentJSON has no comments — strip them before parsing
"a": NaNOnly numbers, strings, booleans, null, arrays and objects are valid
"name": "O’Brien"Smart quotes from a word processor — replace with plain ones

JSON-LD and structured data

One special case deserves attention: JSON-LD, the format search engines use for schema markup. It lives inside an HTML script tag, so a single unescaped character can break both the markup and the page. Two habits prevent most problems:

  • Validate the JSON on its own first — paste the block into the formatter before it goes into a template.
  • Escape closing tags — never write a literal </script> inside a JSON string.

If the data starts life in a spreadsheet, convert it first with the CSV to JSON Converter rather than typing it by hand. The fewer human keystrokes, the fewer unescaped quotes.

A final tip: keep a copy of every payload that worked. Debugging is half the effort when you can compare against the version that was definitely valid.

Frequently asked questions

What is the most common JSON error?
Trailing commas and single quotes. Both are valid in JavaScript, which is why they are the most frequent syntax errors in JSON payloads.
Does JSON allow comments?
No. Comments must be removed before parsing; use a separate documentation file or a JSON5-aware tool during development.
Why does my JSON-LD not show in search results?
Rich results require the underlying data to be valid and eligible for that feature. Validate the JSON itself first, then the structure against the schema type you are using.

Tools used in this guide

Keep reading