JSON tools · 6 min read
JSON formatter: pretty, minified, and actually valid
A JSON formatter does three jobs, and it is worth knowing which one you actually need: it makes dense JSON readable, it makes readable JSON compact, and it tells you exactly where a file stopped being valid JSON. Most people reach for a formatter because something is broken — and the error message, not the pretty printing, is the part that saves the afternoon.
Updated
Pretty-print: for humans and pull requests
Indented JSON is reviewable JSON. Two spaces is the convention in most JavaScript codebases and matches the default in `JSON.stringify(value, null, 2)`; four spaces suits editors configured that way. The formatting choice matters less than consistency, because mixed indentation turns every later diff into noise. If your JSON is generated, set the indentation in the generator once and let the formatter enforce it locally for pasted payloads.
Minify: for payloads on the wire
Whitespace in JSON is optional, so stripping it is free savings. On a 200 KB API response the difference is typically 15–30 percent of bytes, which matters when the budget is a mobile connection or a cache header you are trying to respect. Minifying is also the right move before storing a payload in a database column or embedding it in a URL — just minify as a build step rather than by hand, since hand-minified JSON is where debugging goes to die.
Validation: the errors you will actually hit
JSON is a deliberately small grammar, which is why its errors are so repetitive. Almost every invalid JSON error traces back to one of five habits picked up from JavaScript or YAML:
- Trailing commas — `{"a": 1,}` is valid JavaScript and invalid JSON.
- Single quotes or unquoted keys — `{a: 'b'}` must become `{"a": "b"}`.
- Comments — `// note` and `/* note */` have no place in JSON at all.
- Unescaped control characters — literal newlines inside a string must be `\n`.
- Concatenated objects — two top-level objects side by side, usually from a log file with one JSON document per line.
A formatter should tell you the line, the column and show the excerpt. “Unexpected token” alone leaves you scrolling; “line 84, column 17 — trailing comma before }” is a fix.
Why validate before you debug
When an integration fails, the instinct is to inspect code. More often the payload itself is malformed: a template emitted a stray comma, a log pipeline truncated a line, or a copy-paste from a document introduced smart quotes. Running the JSON formatter first separates “the data is wrong” from “the code is wrong” in seconds, and the exact line number usually points straight at the template that produced it.
Large files and privacy
API responses and database exports frequently contain tokens, personal fields or customer data. A server-side JSON formatter means uploading that payload to a third party to have it handed back — a data-protection question with no upside, since formatting is a trivial local operation. The YamlBox JSON formatter parses in the browser with no network calls, so it works offline and keeps your payload on your machine; the same page gives you indentation choices, key sorting for stable diffs, and live statistics such as depth and key count.
JSON Formatter — frequently asked questions
What is the difference between formatting and validating JSON?
Formatting only changes whitespace and is always safe once the document parses. Validating is the check that it parses at all — a formatter that cannot parse your input will report a line and column instead of producing output, and that report is the useful part.
How much smaller is minified JSON?
Typically 15–30 percent, depending on how deeply nested the document is and how long the keys are. Minifying is lossless: whitespace between tokens carries no meaning in JSON, so a minified document parses to exactly the same value.
Is it safe to format JSON containing secrets in the browser?
Yes, when the formatter runs entirely client-side. There is no upload and no request to a server, so tokens in the payload stay in your tab — and the page keeps working when the network is off, which you can verify yourself.
Tools mentioned in this post
Keep reading
6 min read
JSON diff: comparing data the way it is actually structured
Compare two JSON payloads with a structural JSON diff that ignores key order and whitespace, highlights moved values, and shows why text diffs mislead.
6 min read
JSON to JSON Schema: from sample payload to contract
Convert JSON to JSON Schema in the browser: infer a draft from a real payload, then harden required fields, formats and enums — plus the limits of inference.
6 min read
YAML to JSON: converting configs without losing your mind
Convert YAML to JSON in the browser with multi-document support and exact error locations — plus the YAML mistakes that quietly break CI pipelines.
- Longer read: YAML vs JSON: When to Use Which (and How to Convert)