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.
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
- Paste it into the formatter The JSON Formatter validates as you paste and points at the failing line rather than an offset.
- Fix the reported error Work from the first error only — later ones are usually knock-on effects.
- Format with 2-space indentation Readable structure makes the next error obvious.
- Compare with the previous known-good version If you have a backup, JSON Diff Checker shows exactly which keys were added, removed or changed.
- 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 wrote | Why 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 |
// comment | JSON has no comments — strip them before parsing |
"a": NaN | Only 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?
Does JSON allow comments?
Why does my JSON-LD not show in search results?
Tools used in this guide
Keep reading
How to Merge PDF Files Free — Without Uploading Them Anywhere
Merge two or more PDFs into one clean document, the order you want, without sending your files to a server.
ImageHow to Compress an Image Without Losing Quality (2026 Guide)
The exact quality settings that shrink a photo by 60–80% with no visible difference — and when to stop.
ImageJPG vs PNG vs WebP: Which Image Format Should You Use?
A decision table for the three formats that matter, plus the one case where PNG beats everything.