Skip to content
DevTinyTools

Payload size

Does minifying JSON actually save bandwidth?

Minifying JSON looks like an obvious win: fewer bytes, faster transfer. Then you measure it behind a real HTTP stack and the saving mostly disappears. These are the measurements, and the cases where the raw-byte reduction still matters.

7 min readTool: JSON Minifier

The measurement

One real document: 400 orders, an array of objects with a consistent shape, 2-space indentation. It was measured raw, minified, and then compressed with both gzip at its highest level and brotli at its default quality.

Size of one document in six forms
FormSizeCompared with
Indented, 2 spaces221,421 B216.2 KB — the baseline
Minified124,588 B43.7% smaller than the indented file
Indented, gzip -910,879 B10.6 KB
Minified, gzip -99,700 Bonly 10.8% smaller than gzipping the indented file
Indented, brotli5,038 B4.9 KB
Minified, brotli4,791 Bonly 4.9% smaller than brotli-compressing the indented file

Read the middle two rows together. Minification removes 96,833 bytes from the raw file — a 43.7% cut that looks excellent until you compress. After gzip the same minification is worth 1,179 bytes, and after brotli it is worth 247 bytes. The whitespace was never the expensive part.

Why the saving disappears

gzip and brotli are back-reference compressors: they look for repeated byte sequences and replace each repeat with a short pointer. Indentation is almost nothing but repeats — the same two spaces, in runs whose length is predictable from the nesting depth — so it costs a handful of pointers instead of 96 KB.

What compresses badly is entropy: unique keys, random IDs, timestamps and free-text values. Those are exactly the bytes minification leaves untouched. That is the whole explanation, and it generalises to almost any JSON payload.

The bigger lever is not minification

Compare the two ways of shrinking the wire size. Minifying on top of gzip saves 10.8%. Switching from gzip to brotli, with no change to the document at all, takes 10,879 bytes down to 5,038 — a 53.7% reduction. Enabling brotli is roughly five times the win, and it is a server configuration change rather than a build step.

The ordering that follows is: enable compression first, remove unused fields second, minify third. Dropping a field nobody reads beats every whitespace decision you will ever make.

Where minifying still wins

  • When compression is off. A surprising number of internal services, misconfigured proxies and CDN rules serve JSON with no Content-Encoding at all. There, the raw 43.7% is real.
  • Storage with size limits. Rows in a database, keys in Redis, entries in localStorage and files on disk are often stored uncompressed, and often have quotas.
  • Message queues and sockets. Payload caps on queues and log pipelines are measured on the uncompressed body. WebSocket frames are not compressed unless permessage-deflate was negotiated.
  • Anything in a URL. A document encoded into a query string or a share link is transferred uncompressed, and every byte counts against a length limit.
  • Signing and hashing. Here minification is about determinism, not size: two serialisations of the same object differ in whitespace, so sign one canonical form and verify that same form.

How to check your own traffic

Open the network panel, click the JSON request, and look at the Size column: it shows the transferred size, and the response headers show whether content-encoding is gzip or br. From a terminal, ask for both and read the header:

curl -sI -H 'Accept-Encoding: gzip, br' https://example.com/data.json \
  | grep -iE 'content-encoding|content-length'

If there is no content-encoding line, the response is going out uncompressed — fix that before spending any time on the minifier. If it says br, you are already at the best point on this chart.

To see the raw numbers for your own document, the JSON Minifier reports character and byte counts before and after, without sending anything anywhere.

Frequently asked questions

So should I stop minifying entirely?
No — minify for storage, logs, URLs and message queues, where compression may not be applied at all. For HTTP responses that are already compressed, the gain is small enough that it should not be your first optimisation.
Why does indentation compress so well?
Indentation is a repeating pattern: the same two spaces, in runs whose length is predictable from nesting depth. gzip and brotli encode that as a handful of back-references, so 96 KB of whitespace costs a few hundred bytes on the wire.
Does the saving depend on the document?
Yes. A document with few repeated keys compresses less, so minification keeps more of its advantage. The numbers here come from a 400-order document with a repeated object shape, which is close to the best case for a compressor and therefore close to the worst case for minification.
Does minifying change the data?
Not if it is done by a real parser rather than a regular expression. The minifier here parses the document and re-serialises it, which removes whitespace and normalises number formatting at the same time — see the precision guide for what normalisation can change.