Formatting
How to minify JSON
Minifying JSON strips every byte that isn't part of the data — the indentation and line breaks that make it readable. The result is identical data in a smaller payload. Here's when it helps and how to do it (and undo it).
Updated July 20263 min read
What minifying does
JSON allows whitespace between tokens for readability, but that whitespace carries no data. Minifying removes all of it — indentation, line breaks, and the spaces after colons and commas:
// pretty-printed (readable)
{
"name": "Ada",
"roles": ["admin", "editor"]
}
// minified (compact)
{"name":"Ada","roles":["admin","editor"]}Both parse to exactly the same object. Minifying is purely a size optimization — it never changes a value.
How to minify JSON in the browser
In the JSON Viewer & Formatter:
- Paste your JSON, or open a file.
- Click Minify to collapse it to a single compact line.
- Copy the result — or click Format to expand it back to a readable, indented document.
In code, the equivalent is JSON.stringify(value) to minify and JSON.stringify(value, null, 2) to pretty-print.
When minifying is worth it
- Network payloads — smaller request and response bodies mean less to transfer. (Note: HTTP compression like gzip/brotli already removes most repeated whitespace, so the win is smaller when compression is on.)
- Embedding JSON in an HTML data attribute, a URL, or a single-line config value where line breaks would be awkward.
- Storage limits — fitting more data into size-capped fields like
localStorageor a database column.
When you're reading or debugging, do the opposite and format (beautify) the JSON instead — minified JSON is hard for humans to scan.
Minifying vs. compression
Minifying removes whitespace at the JSON level; gzip/brotli compress the bytes at the transport level. They stack, but compression does most of the heavy lifting for repetitive text. If your server already compresses responses, minify for the cleaner single-line form rather than expecting a dramatic size drop.
Frequently asked questions
What does minifying JSON do?
Minifying removes all optional whitespace — indentation, line breaks, and spaces between tokens — so the JSON becomes the smallest valid representation of the same data.
Does minifying change the data?
No. Minifying only removes whitespace between tokens. The parsed value is identical; only the byte size changes.
How much smaller is minified JSON?
It depends on how much indentation the source had, but pretty-printed JSON is often 20–50% larger than its minified form. The savings are biggest for deeply nested documents.
Can I expand minified JSON again?
Yes. Minifying is reversible — a formatter re-adds indentation to make it readable. No information is lost.