The Complete Guide to JSON Formatting and Validation
Pretty-print, validate and debug JSON with confidence — from the syntax rules to the most common production errors.
Daniel Osei
Software Engineer & Developer Tools
JSON is the lingua franca of APIs, and formatting it well is the difference between "works" and "works and is maintainable". This guide covers the rules, the mistakes and the workflow we use to debug JSON every day.
The syntax rules (all of them)
- Objects use {} with "key": value pairs separated by commas.
- Arrays use [] with values separated by commas.
- Keys must be double-quoted strings.
- Strings must be double-quoted; escapes use backslashes.
- Numbers have no quotes and no leading zeros.
- Valid values: string, number, boolean, null, array, object.
- No comments. No trailing commas.
The five most common errors
| Error | Example | Why it fails |
|---|---|---|
| Trailing comma | {"a":1,} | Parser expects a value after the comma |
| Unquoted key | {a:1} | Keys must be strings |
| Single quotes | ['a'] | JSON only accepts double quotes |
| Comments | {/* note */} | JSON has no comment syntax |
| NaN / undefined | {"x": NaN} | Only literal values are allowed |
The debugging workflow
- Paste the JSON into the formatter and read the highlighted error location.
- Fix the reported issue — it is almost always at or just before the highlight.
- Re-format and inspect the structure with branches collapsed.
- Trace one path from root to a leaf to verify the data shape.
- Minify only when you are ready to ship.
Pretty vs minified: both are the same data
Formatting only changes whitespace. The parser sees identical values either way. Use pretty for humans and debugging, minified for payloads and storage. One click switches between them.
If the formatter passes, the JSON is valid — the tool uses a full parser, not a regex. Pass means pass.
What is the difference between JSON and JSONL?
JSONL is one JSON value per line, used for streaming and logs. The formatter handles single JSON documents; for JSONL, validate each line separately.
Tools for this task
JSON Formatter
PopularPretty-print, validate and minify JSON — securely in your browser.
Encode text to Base64 and decode it back — with UTF-8 support.
Encode and decode URLs, query strings and components.
Keep reading
JSON Formatter: A Beginner's Tutorial (With Real Examples)
JSON is everywhere, but minified JSON is unreadable. Learn to format, validate and understand JSON in under ten minutes.
JSON Formatter vs Minifier: When to Use Each
Both transform JSON — one for humans, one for machines. Here is when each matters and why the difference is not cosmetic.
