What Is JSON?
JSON (JavaScript Object Notation) is the de-facto standard for data exchange on the web. It is human-readable, language-agnostic, and natively supported in every modern programming language. APIs, config files, databases, and logs all use JSON.
How Formatting Works
// Step 1 — Validate by parsing
const obj = JSON.parse(rawInput); // throws SyntaxError if invalid
// Step 2 — Pretty print
const pretty = JSON.stringify(obj, null, 2);
// Step 3 — Minify
const minified = JSON.stringify(obj);
The null, 2 arguments tell JSON.stringify to use 2-space indentation. Passing no indent produces a compact single-line output.
Common JSON Errors & Fixes
- Trailing comma:
{"a":1,}— Remove the comma after the last value. - Single quotes:
{'key':'val'}— JSON requires double quotes only. - Unquoted keys:
{key:"val"}— Keys must be double-quoted strings. - Comments: JSON does not support
// comments. Use JSON5 or strip them first. - Undefined / NaN: These JS values are not valid JSON — replace with
null.
When to Minify vs Pretty Print
- Pretty print: When debugging, reading API responses, or writing config files.
- Minify: Before shipping to production — reduces payload size, improving API response times.
JSON vs XML vs YAML
- JSON: Fast, compact, great for APIs and JavaScript.
- XML: Verbose, supports attributes and namespaces — used in legacy enterprise systems.
- YAML: Human-friendly, supports comments — popular for config files (Docker, GitHub Actions).
Validate, format, and minify any JSON instantly — 100% client-side, your data stays private.
Try the JSON Formatter →