Does minifying JSON still matter with gzip and Brotli?
Measured: how many bytes minifying JSON saves before and after gzip, Brotli, and Zstandard, and when it is still worth doing for an API response.
Published By Muhammad Sohail
Short answer
Usually only a little. In my measurements, minifying a sample JSON API response made it 40.0% smaller on its own, but only 5.5% to 13.5% smaller once compressed. It matters more without compression: in nginx, gzip is off by default, and when enabled gzip_types defaults to text/html only.
When an app or a website asks a server for data, the answer often comes back as JSON. A server is simply the computer that answers those requests. JSON is a plain text format for data: names and values, such as "city": "Lahore", grouped with braces and brackets.
Developers can minify JSON before sending it. Minifying means deleting the spaces and line breaks that only exist to make the text easier for people to read. But web servers can also compress what they send, which squeezes the text into fewer bytes for the trip. So if the response is compressed anyway, is minifying still worth the effort?
I wanted to know whether minifying still pays off once a response is compressed, so I measured it. Every number in this article comes from a script I ran on my own machine.
If you do not write code, you can skip every code block below. The text around each one explains what it shows, so you can still follow the whole article.
What minifying JSON removes
JSON can be written in two ways that hold exactly the same data.
Pretty-printed JSON puts each value on its own line and indents nested parts with spaces, so a person can read it. Minified JSON puts everything on one line with no extra spaces, so it is shorter. Spaces, tabs and line breaks are together called whitespace.
The official JSON standard is RFC 8259. An RFC is a numbered document that defines an internet standard. It says whitespace around the six characters that give JSON its structure (the braces, the brackets, the colon and the comma) is insignificant. Insignificant means a program that reads the JSON ignores it. So minifying removes only that whitespace, and the data stays exactly the same.
Here is the same small piece of data written both ways. You do not need to run anything; just compare the two. First pretty-printed with two spaces:
{
"id": "ord_000001",
"status": "paid",
"total": "129.90",
"items": [
{ "sku": "SKU-1042", "quantity": 2 }
]
}And the same data minified:
{"id":"ord_000001","status":"paid","total":"129.90","items":[{"sku":"SKU-1042","quantity":2}]}If you write JavaScript, the programming language that runs in web browsers, its built-in JSON.stringify function can produce both. JSON.stringify(value) gives the minified form, and JSON.stringify(value, null, 2) indents with two spaces. The last argument can also be a string, such as a tab, and MDN documents that numbers above 10 are treated as 10.
If you want to see the difference on your own data, the JSON Minifier shows the size before and after.
Minifying should never break your data. If a minified file fails to parse, a program cannot read it as JSON. The JSON Validator shows the exact line and column of the error.
Why compression already removes most of it
Compression means rewriting data so it takes fewer bytes, in a way that can be undone exactly. A simple way to picture it: instead of copying out a line you already wrote, you write “same as above”. The reader can rebuild the original from the shorter version.
Websites use three common compression methods: gzip, Brotli and Zstandard. Your browser tells the server which ones it understands, and the server picks one.
gzip is defined in RFC 1952 and uses a method called DEFLATE, defined in RFC 1951. DEFLATE looks for text that already appeared earlier and replaces the repeat with a short pointer back to it. That is the “same as above” trick.
Indentation repeats the same few runs of spaces line after line. Every line at the same depth starts with exactly the same spaces, so DEFLATE can replace most of them with short pointers. That is why indentation costs much less after compression than it seems to.
Brotli (RFC 7932) uses the same pointer idea and adds two more techniques. Huffman coding gives common characters shorter codes. Context modeling uses the characters just before a position to predict what comes next. Zstandard (RFC 8878) is also built on finding repeated data.
Compression therefore shrinks indentation a lot on its own. The useful question is how much minifying still adds on top of it.
How I measured it
To answer that, I compressed the same JSON twice: once pretty-printed and once minified. Then I compared the sizes.
Test files
All sizes in this article are in bytes. A byte is the basic unit of computer storage. One plain English letter or one space takes one byte, and a kilobyte is about a thousand bytes.
I did not use real company data. Instead, a script made five JSON files from a fixed seed, which is a starting number for a random generator. The same seed always produces exactly the same files, so anyone who runs the script gets the same bytes. Because these are generated samples, your own JSON will give different numbers.
One of the files is an API response. An API (application programming interface) is a set of addresses that a program can call to get or send data. The JSON it sends back is called the API response.
| File | What it stands for | Pretty-printed (bytes) | Minified (bytes) |
|---|---|---|---|
| user.json | one small object, a user profile | 346 | 273 |
| orders-page.json | a sample paginated API response: 50 orders with nested items, plus page metadata and links | 44,999 | 27,019 |
| catalog.json | a large list of 3,000 products | 578,271 | 377,270 |
| readings.json | 10,000 numeric sensor readings | 457,851 | 277,850 |
| config.json | an object nested 6 levels deep | 108,234 | 45,905 |
What this means: minifying on its own makes every file smaller. The API response shrinks from 44,999 bytes to 27,019 bytes, and the deeply nested config file shrinks the most, from 108,234 bytes to 45,905 bytes.
The pretty-printed versions use two spaces of indentation. A separate test further down compares four spaces and tabs.
Settings and versions
Each compression method has levels. A higher level tries harder to make the result small, and it takes more computer time to do so. I used the default level of each tool, because defaults are what a setup runs unless someone changes them.
Two tools set those defaults here. nginx is web server software: the program that receives requests and sends back responses. Node.js is a program that runs JavaScript outside the browser, and I used it to run the measurement.
| Setting | Why this level |
|---|---|
| gzip level 1 | the default of nginx (gzip_comp_level 1) |
| gzip level 6 | the default of zlib and of Node.js |
| Brotli quality 11 | the default of Node.js (BROTLI_DEFAULT_QUALITY) |
| Zstandard level 3 | the default of Node.js (ZSTD_CLEVEL_DEFAULT) |
What this means: gzip appears twice because nginx and Node.js use different default levels, 1 and 6. Brotli and Zstandard each appear once, at the defaults Node.js uses, 11 and 3.
Cloudflare is a service that sits between visitors and a website’s own server and can compress responses on the way. It does not publish the levels it uses, so I did not guess them.
I ran the script with Node.js v26.4.0, which bundles zlib 1.3.2.1, Brotli 1.2.0 and Zstandard 1.5.7, on Windows x64. zlib is the library that does the gzip compression. The Zstandard part of Node.js is still marked experimental in the v26 documentation, which means its details may still change.
The script also checks its own work. Every pretty-printed and minified pair must contain the same data, and every compressed file must turn back into exactly the original when it is decompressed. All checks passed.
The core of the measurement is short. You only need it if you want to repeat the test yourself. It reads a JSON file and prints the compressed sizes of its pretty-printed and minified versions:
import { readFileSync } from 'node:fs';
import zlib from 'node:zlib';
const data = JSON.parse(readFileSync('orders-page.json', 'utf8'));
const pretty = Buffer.from(JSON.stringify(data, null, 2));
const minified = Buffer.from(JSON.stringify(data));
const gzip6 = (bytes) => zlib.gzipSync(bytes, { level: 6 }).length;
const brotli11 = (bytes) =>
zlib.brotliCompressSync(bytes, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11 } }).length;
const zstd3 = (bytes) =>
zlib.zstdCompressSync(bytes, { params: { [zlib.constants.ZSTD_c_compressionLevel]: 3 } }).length;
console.log(gzip6(pretty), gzip6(minified));
console.log(brotli11(pretty), brotli11(minified));
console.log(zstd3(pretty), zstd3(minified));Results
This table shows how much smaller the minified file is than the pretty-printed one. The first number column is without compression. The other columns are after each compression setting.
| File | Uncompressed | gzip 1 | gzip 6 | Brotli 11 | Zstandard 3 |
|---|---|---|---|---|---|
| user.json | 21.1% | 9.6% | 8.1% | 5.3% | 11.3% |
| orders-page.json | 40.0% | 13.5% | 10.0% | 5.5% | 10.1% |
| catalog.json | 34.8% | 12.1% | 10.4% | 4.5% | 9.0% |
| readings.json | 39.3% | 4.8% | 7.7% | 5.4% | 2.1% |
| config.json | 57.6% | 23.9% | 21.4% | 11.1% | 25.5% |
What this means: without compression, minifying saves between 21.1% and 57.6%. After compression the saving drops to between 2.1% and 25.5%. It is smallest with Brotli quality 11, between 4.5% and 11.1%.
The API response in bytes
| orders-page.json | Uncompressed | gzip 1 | gzip 6 | Brotli 11 | Zstandard 3 |
|---|---|---|---|---|---|
| Pretty-printed (2 spaces) | 44,999 | 6,799 | 5,525 | 4,304 | 5,751 |
| Minified | 27,019 | 5,882 | 4,973 | 4,067 | 5,170 |
What this means: compression does most of the work. gzip level 6 alone takes the pretty-printed response from 44,999 bytes to 5,525 bytes. Minifying first brings it down to 4,973 bytes.
Indentation
Indentation can be written with two spaces, four spaces or tab characters. I tried all three on the API response. These are the sizes in bytes:
| orders-page.json | Uncompressed | gzip 1 | gzip 6 | Brotli 11 | Zstandard 3 |
|---|---|---|---|---|---|
| 2 spaces | 44,999 | 6,799 | 5,525 | 4,304 | 5,751 |
| 4 spaces | 59,687 | 7,312 | 5,835 | 4,400 | 5,994 |
| Tabs | 37,655 | 6,430 | 5,378 | 4,225 | 5,541 |
| Minified | 27,019 | 5,882 | 4,973 | 4,067 | 5,170 |
What this means: four spaces make the uncompressed response much larger, 59,687 bytes against 44,999. After Brotli 11 the two are close: 4,400 bytes against 4,304.
And this is how much minifying saves from each style:
| Minifying from | Uncompressed | gzip 1 | gzip 6 | Brotli 11 | Zstandard 3 |
|---|---|---|---|---|---|
| 2 spaces | 40.0% | 13.5% | 10.0% | 5.5% | 10.1% |
| 4 spaces | 54.7% | 19.6% | 14.8% | 7.6% | 13.7% |
| Tabs | 28.2% | 8.5% | 7.5% | 3.7% | 6.7% |
What this means: the more indentation a file has, the more minifying removes. From four spaces it saves 14.8% after gzip level 6, and from tabs only 7.5%.
What the numbers mean
Without compression
If the JSON travels without compression, minifying saves a lot. In my samples it saved between 21.1% and 57.6% of the size, and 40.0% for the API response.
With compression
Once the response is compressed, most of that saving is gone. With gzip level 6, minifying saved between 7.7% and 21.4%. With Brotli quality 11 it saved between 4.5% and 11.1%, and with Zstandard level 3 between 2.1% and 25.5%. For the API response it saved 10.0% with gzip 6, 5.5% with Brotli 11 and 10.1% with Zstandard 3.
Two exceptions
The numbers-heavy file, readings.json, does not follow a neat pattern. With gzip level 1 minifying saved 4.8%, which is less than the 7.7% it saved with gzip level 6. With Zstandard it saved only 2.1%. So I would not turn these results into a rule about compression levels.
The deeply nested file, config.json, is where minifying still clearly helps after compression. Indentation grows with every level of nesting, so there is more of it to remove. Minifying saved 21.4% even after gzip level 6 and 11.1% after Brotli quality 11.
Very small responses
Very small responses are not compressed at all. nginx does not gzip responses shorter than 20 bytes (its gzip_min_length setting). Cloudflare compresses only responses of at least 48 bytes for gzip and 50 bytes for Brotli and Zstandard.
Is your JSON actually compressed?
All of this assumes the response is compressed. Often it is not, and then the uncompressed numbers above apply.
In nginx, gzip is off by default, and when enabled gzip_types defaults to text/html only. gzip_types is the setting that lists which kinds of content nginx compresses, and text/html means web pages, so JSON is not on that list. With nginx’s own defaults, a JSON API is therefore sent without compression. To change that, turn gzip on and add application/json (the label for JSON content) to gzip_types.
Cloudflare compresses application/json responses for visitors whose browser supports it. According to its documentation, the default method is Zstandard on the Free plan, Brotli on Pro and Business, and gzip on Enterprise. Cloudflare calls your own server the origin. If the origin already sends Brotli or gzip, Cloudflare keeps that encoding, as long as the visitor supports it and no Cloudflare feature has to change the content. I checked these details against Cloudflare’s documentation on 27 November 2026.
How can you tell what your server does? Every response comes with HTTP headers: short labelled lines of information sent before the content itself. If the response was compressed, a header called content-encoding names the method, for example gzip, br for Brotli, or zstd for Zstandard.
The easiest check needs no code. Open your browser’s developer tools, the built-in inspection panel (in Chrome, Edge and Firefox you can press F12; on a Mac, Cmd+Option+I). Open the Network tab, load the page or call the API, and select the request. Then look for content-encoding in the response headers.
If you use a terminal, curl does the same check. curl is a command line program that sends a request and shows the reply. This command asks for a compressed response and prints only the headers, so you can run it against your own address:
curl -s -o /dev/null -D - -H "Accept-Encoding: br, gzip, zstd" https://api.example.com/ordersLook for a content-encoding header in the output. If there is none, the response was sent uncompressed. The part /dev/null tells curl to throw the content away, so only the headers are shown. On Windows Command Prompt, replace /dev/null with NUL.
When minifying still makes sense
Minify when the JSON is not compressed on its way to the client, because that is where it saves the most. It is also worth it for deeply nested data, where it still saved 21.4% after gzip in my test. And it helps for JSON that you store or log without compression, where the uncompressed numbers apply.
For the sample API response, once it was compressed, minifying saved 5.5% to 13.5% in my measurements. That is still a saving, but a small one, and pretty-printed responses are easier to read while you look for a problem. If you work with minified responses, the JSON Formatter turns them back into indented text in your browser.
What to remember
- Minifying JSON removes only whitespace. The data stays exactly the same.
- Without compression, minifying makes JSON much smaller: 40.0% for the API response in my test.
- With compression, the extra saving is small: 5.5% to 13.5% for the same response.
- Check whether your responses are compressed at all. Look for content-encoding in the response headers.
- Deeply nested JSON still benefits after compression: 21.4% with gzip level 6 in my test.
Sources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
www.rfc-editor.org
- RFC 1951: DEFLATE Compressed Data Format Specification version 1.3
www.rfc-editor.org
- RFC 1952: GZIP file format specification version 4.3
www.rfc-editor.org
- RFC 7932: Brotli Compressed Data Format
www.rfc-editor.org
- RFC 8878: Zstandard Compression and the 'application/zstd' Media Type
www.rfc-editor.org
- MDN: JSON.stringify()
developer.mozilla.org
- MDN: Content-Encoding
developer.mozilla.org
- Node.js v26 documentation: Zlib
nodejs.org
- nginx: Module ngx_http_gzip_module
nginx.org
- Cloudflare: Content compression
developers.cloudflare.com
Tools used in this article
- JSON Minifier
Shrink JSON by removing whitespace without changing any values, and see how much smaller it gets.
- JSON Formatter
Format and beautify JSON with your choice of indentation, and find syntax errors by line and column.
- JSON Validator
Check JSON for errors with line, column, and code context, and catch duplicate keys and unsafe large numbers.