JSON that is minified to one line or has a trailing comma, single quotes, or an unquoted key looks valid to the eye but fails every parser with "Unexpected token" — and the error is on line 3, column 15, not where the file was copied. A JSON formatter and validator that beautifies with indentation, validates per RFC 8259 and ECMA-404, and pinpoints the exact line, column, and fix turns a wall of text into readable, correct JSON in seconds. It handles 100KB+ payloads, large arrays, and nested objects without installing an editor plugin.
This A-to-Z guide explains how to format and validate JSON online — what formatting vs validation means, the common errors that break parsers and how to fix them, the formatter features (beautify, minify, sort, indent), and a 3-step workflow to paste, fix, and copy — with references to JSON.org, MDN: JSON, and RFC 8259.
What Is JSON Formatting vs Validation?
Formatting (beautify/minify) changes whitespace for readability without changing data. Beautify adds indentation and line breaks (e.g., 2-space indent) so a minified one-line {"name":"Anna","age":28} becomes a scannable 5-line block. Minify does the reverse — one line, no spaces — for smallest payload. Sort keys alphabetizes for diff and review. None of these change the parsed value — JSON.parse(beautified) === JSON.parse(minified).
Validation checks strict JSON syntax per RFC 8259: double quotes only for strings and keys, no trailing commas, no comments, no single quotes, no unquoted keys, and numbers, booleans, null, objects, and arrays only as values. Per JSON.org, JSON is a strict subset of JavaScript — {name: "Anna"} is valid JS but invalid JSON. The validator enforces the strict subset and reports the first error's line and column per the ECMA-404 grammar.
Common JSON Errors — And How to Fix Them
| Error | Invalid Example | Fix |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Remove comma before } or ] → {"a": 1, "b": 2} |
| Single quotes | {'name': 'Anna'} | Use double quotes → {"name": "Anna"} |
| Unquoted keys | {name: "Anna"} | Quote keys → {"name": "Anna"} |
| Comments | {"a": 1 // comment} | Remove comments (JSON has none) — use "_comment": "..." if needed |
| Trailing text | {"a": 1} extra | One value per parse — wrap in array if multiple |
| NaN / Infinity / undefined | {"v": NaN} | Use null or quoted string — JSON numbers are finite |
How the validator pinpoints: "Parse error on line 3, column 15: Unexpected token } — trailing comma at "b": 2," with the line highlighted and the fix shown as "b": 2 without the comma. This beats reading the raw Unexpected token from JSON.parse in the console, which gives line but not the human fix.
Why these errors happen: JavaScript tolerates trailing commas and single quotes; JSON does not. Copying from JS code, Python dicts (single quotes), or JSON5/JSONC files (comments) introduces them. The validator normalizes to strict JSON.
Formatter Features — Beyond Beautify
- Beautify (2 or 4 spaces, or tabs): Indented, line-broken, sorted keys optional — for reading, diff, and code review. A 10KB minified API response becomes 300 scannable lines where a missing comma is visible.
- Minify: One line, no unnecessary whitespace — for smallest payload over the wire or storage. Reversible — beautify restores readability without data loss.
- Sort keys: Alphabetical key order —
{"b":2,"a":1} → {"a":1,"b":2}— for deterministic diff and snapshot testing. Per MDN: JSON.stringify(), key order is insertion order in JS, but sorting makes diffs stable. - Compact vs expanded arrays: Option to keep small arrays on one line or break each element — e.g.,
"tags": ["a","b","c"]vs multi-line for large arrays. - Large files: Handles 100KB+ and deeply nested objects without freezing, with virtualized rendering and chunked parsing where needed.
How to Format and Validate JSON Online — 3 Steps
- Paste JSON: From an API response, file, editor, or
fetchoutput. The tool accepts the raw string — minified, pretty, or broken — and detects the first error without needing to save a file. - Validate and fix: The validator shows
Valid ✓or the exact line, column, and fix hint (e.g., "single quotes on line 2, col 1 → use double quotes"). Fix the highlighted line — e.g., change'name'to"name"and remove the trailing comma — and re-validate; the line count updates live as you type, so the fix is confirmed before copying. - Copy formatted: Choose beautified (2-space default, or 4/tabs), minified, or sorted, then copy. The formatted output preserves strings, numbers, booleans, null, objects, and arrays per RFC 8259, with Unicode escaped only where required.
Beyond basic formatting: The online formatter also offers JSON repair for common non-strict inputs (single quotes → double, unquoted keys → quoted, trailing commas removed) with a diff view — useful for converting JS object literals or Python dict dumps into strict JSON without manual search-replace.
JSON vs JavaScript Object Literal — Don't Confuse Them
| Feature | JSON (RFC 8259) | JS Object Literal |
|---|---|---|
| Keys | Double-quoted strings only | Unquoted or single/double |
| Strings | Double quotes only | Single or double |
| Trailing comma | Forbidden | Allowed (ES5+) |
| Comments | Forbidden | // and /* */ |
| Values | String, number, bool, null, object, array only | + undefined, NaN, Infinity, functions |
Copying a JS object literal directly into a JSON parser fails on the first of these differences — the validator flags the exact line so the conversion is mechanical, not guesswork.
Common Workflows — When to Use Which Format
- Debugging an API response: Paste the minified response, beautify with 2 spaces, and scan for a missing comma or wrong type — the line numbers make the bug visible.
- Preparing a payload for curl or fetch: Minify to one line for
curl -d '{"a":1}'or copy as a JS object forfetchbody. - Diffing two JSON files: Beautify both with sorted keys, then diff — key order no longer pollutes the diff.
- Storing in a database: Minify for smallest storage, or store as
jsonb(PostgreSQL) which normalizes whitespace server-side.
FAQs About Formatting and Validating JSON
How do I format JSON online?
Paste JSON into a JSON formatter, choose 2 or 4-space indent (or tabs), and copy the beautified output. The formatter validates first and shows the error line if invalid.
How do I validate JSON?
Paste into a JSON validator to check strict RFC 8259 compliance. If invalid, the validator shows the exact line, column, and fix hint (e.g., trailing comma, single quotes) before formatting.
Why does my JSON fail with "Unexpected token"?
Most often a trailing comma, single quotes, unquoted keys, or comments — all valid in JS but invalid in JSON. The validator pinpoints the line and shows the strict fix.
What is the difference between JSON and JavaScript object?
JSON is a strict text format with double-quoted keys/strings, no trailing commas, and no comments. A JS object literal is more permissive. Use a formatter to convert JS literals to strict JSON.
Can I format large JSON files online?
Yes — the tool handles 100KB+ and deeply nested structures with chunked parsing. For very large files (MBs), use a streaming parser or jq locally: cat file.json | jq .
Should I sort JSON keys?
For diff and snapshot testing, yes — alphabetical order makes diffs deterministic. For API payloads, preserve the original order unless the API requires sorted keys.
Conclusion
Formatting and validating JSON is whitespace vs strict syntax — beautify for readability, validate for correctness, and fix the exact line the parser flags. A formatter that validates per RFC 8259, pinpoints line and column, and offers beautify/minify/sort covers the daily loop from API response to copy-paste payload.
Paste the next JSON — minified or broken — to get instant validation and the formatted, correct version ready to copy.