JSON Formatter โบ Guides
Is minifying JSON still worth it once gzip or Brotli is on?
Minifying JSON means removing the spaces and line breaks that make it readable. On disk the saving is large, and the advice to minify everything follows from that. But JSON sent by a web server is often compressed on the way, and compression is very good at exactly the thing minifying removes: the same run of spaces repeated on every line. We measured five documents in four layouts, before and after compression, to see how much of the saving is left.
Short answer: without compression, JSON indented with 2 spaces was 26 to 140% bigger than the minified version. After gzip the gap fell to 3 to 21%, and after Brotli to 2 to 8%. Gzip itself made the minified files 61 to 88% smaller. Turn compression on first, then minify what a program reads, and keep indentation where people read the file.
What we measured
Five documents were written out in four layouts with JSON.stringify: minified, 2 spaces, 4 spaces and tab. Four were generated for the test: an API response with 2,000 user records, a map line with 20,000 longitude and latitude pairs, a settings file nested 6 levels deep, and a log of 5,000 short events. The fifth is a real file, the tool list this site serves at /tools.json, as it was on the day of the test. Each of the 20 files was then compressed with gzip at level 6, the zlib default, gzip at level 9, and Brotli at quality 11, using zlib 1.3.1 and Brotli 1.1.0 in Node.js 22.23.4. Sizes are in KB of 1,000 bytes.
Before compression: indentation is expensive
| Document | Minified | 2 spaces | 4 spaces | Tab |
|---|---|---|---|---|
| API response, 2,000 users | 426.3 KB | 640.3 KB | 808.3 KB | 556.3 KB |
| Map line, 20,000 points | 455.7 KB | 1,095.7 KB | 1,655.8 KB | 815.7 KB |
| Config, 6 nesting levels | 124.0 KB | 239.6 KB | 338.8 KB | 190.0 KB |
| Log, 5,000 events | 284.7 KB | 434.7 KB | 534.7 KB | 384.7 KB |
| Tool list (tools.json) | 17.4 KB | 21.9 KB | 25.1 KB | 20.2 KB |
The map line more than doubled with 2 spaces because every coordinate pair became four lines, each with its own indentation. The tool list grew least: 77% of its minified bytes are quoted text such as names and descriptions, so whitespace is a small part of the file.
After compression: most of the gap disappears
The next table shows how much bigger the 2-space file is than the minified file, at each stage.
| Document | Not compressed (%) | gzip level 6 (%) | Brotli quality 11 (%) |
|---|---|---|---|
| API response | 50.2 | 6.2 | 2.9 |
| Map line | 140.5 | 14.5 | 7.9 |
| Config | 93.2 | 21.4 | 7.1 |
| Log | 52.7 | 14.1 | 3.1 |
| Tool list | 25.9 | 2.6 | 2.2 |
In bytes, minifying the API response saved 214.0 KB on disk and 6.2 KB after gzip. For the map line it was 640.0 KB against 16.2 KB, and for the tool list 4.5 KB against 0.2 KB. The saving does not vanish, because the compressor still has to record where each line break and indent goes, but it shrinks to a small fraction.
The other layouts followed the same pattern. With gzip at level 6, 4 spaces cost 3.5 to 28.5% more than minified and tab cost 1.8 to 13.8%. The deeply nested settings file was the worst case in every layout.
Compression matters far more than minifying
| Document | Minified, not compressed | 2 spaces, gzip level 6 | Minified, gzip level 6 | Minified, Brotli 11 |
|---|---|---|---|---|
| API response | 426.3 KB | 107.5 KB | 101.2 KB | 76.0 KB |
| Map line | 455.7 KB | 127.6 KB | 111.5 KB | 76.0 KB |
| Config | 124.0 KB | 33.2 KB | 27.3 KB | 23.7 KB |
| Log | 284.7 KB | 38.7 KB | 33.9 KB | 27.6 KB |
| Tool list | 17.4 KB | 6.9 KB | 6.7 KB | 5.7 KB |
For every document, the indented file with gzip was much smaller than the minified file without it: 107.5 KB against 426.3 KB for the API response. Gzip at level 6 made the minified files 61 to 88% smaller, and Brotli at quality 11 made them 67 to 90% smaller. Moving from gzip to Brotli also saved more than minifying did after gzip in four of the five documents. If a server sends JSON without compression, fixing that is the first step, and minifying is the second.
When minifying is still worth doing
- Responses that only programs read. Minified output is the default of
JSON.stringifyand of many server libraries, so it costs nothing, and the saving adds up across many requests. - Anything stored or sent without compression. Browser storage, a database text column, a message queue, a value embedded in a page or a URL. Here the full uncompressed gap applies.
- Size limits counted before compression. Some storage systems and request limits count the uncompressed bytes.
- Memory and parsing on small devices. The receiver has to hold the uncompressed text before parsing it, however small it was on the wire.
When to keep the indentation
- Files people edit or review. Settings files, translation files and test fixtures kept in version control. One value per line makes changes easy to read, and a minified file shows every edit as one changed line.
- Debugging. A response you are inspecting by eye. Format it on your side instead of asking the server to send it indented.
- Small files served compressed. For the tool list, minifying saved 0.2 KB after gzip.
To switch a pasted document between the two layouts, use the JSON formatter: Minify removes the whitespace and Beautify puts it back with 2 spaces, 4 spaces or a tab.
Limits of this test
Four of the five documents were generated, with random names, numbers and identifiers. Real data may repeat more, and then both compression and the remaining gap will differ. The compressors were run on whole files at fixed settings. A server that compresses responses as they are produced may use a lower Brotli quality than 11 and get results closer to the gzip columns. The test measured size only, not the time to compress, send or parse.
The measurements are in minify-compression.csv: one row per document and layout, with columns document, format, raw_bytes, gzip6_bytes, gzip9_bytes and brotli11_bytes.
Common questions
Does minifying change the data?
Removing whitespace does not. Spaces, tabs and line breaks between values have no meaning in JSON, so a parser reads the same values from both versions, and spaces inside quoted strings are left alone. A tool that parses the text and writes it out again, as our formatter does, also rewrites numbers in a standard form, so 1.0 becomes 1.
How do I know whether a response was compressed?
Open the browser's developer tools, select the request in the Network panel and look at the response headers. A value such as Content-Encoding: gzip or br means it was compressed. The panel also shows the transferred size next to the uncompressed size.
Is a tab smaller than 2 spaces?
Yes, in every document we tested, both without compression and after gzip. Without compression, tab-indented files were 16 to 79% bigger than minified, against 26 to 140% for 2 spaces.
Should I shorten the key names too?
That is a separate change from minifying, and it makes the data harder to read and maintain. Repeated key names are the kind of repetition compressors handle well, so measure the compressed size before deciding.
References
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- RFC 1952: GZIP file format specification
- RFC 7932: Brotli Compressed Data Format
- MDN: Content-Encoding header
Figures without a source link come from the steps shown on this page. Companion tool: JSON Formatter. Spotted an error? Write to help@glowhalo.org.