Skip to content
Emojar โ€“ free online tools
โ† All posts

Developer Tools guide

Does Minifying JSON Still Matter If You Use Gzip?

ยท 4 min read

JSONPerformanceMyths

Minifying JSON removes every space, tab and line break between tokens. Measured as raw text, that often makes a pretty-printed file 25โ€“40% smaller. Once HTTP compression like gzip or Brotli is applied, though, the gap usually shrinks to single digits. So minifying is still worth doing, but it's rarely the big win people expect. Its real value is elsewhere: storage, embedding, and anywhere compression doesn't happen.

Here are some common beliefs about JSON minification, checked against real measurements.

Myth 1: "Minifying cuts my API payload by a third"

That's true for raw bytes and mostly false for bytes on the wire. To check, I generated an array of 200 user records (id, name, email, a boolean, a roles array and a nested address) and measured it three ways:

Format Raw size Gzipped Brotli
Pretty-printed, 4 spaces 56,705 B 2,916 B 1,508 B
Pretty-printed, 2 spaces 44,705 B 2,778 B 1,429 B
Minified 28,304 B 2,592 B 1,309 B

Minifying cut the raw text by 37% compared with 2-space indentation. After gzip, the difference was 186 bytes, about 7%. Indentation is extremely repetitive, and repetition is exactly what compression algorithms remove.

So if your server already compresses responses, minifying your API output is a small optimization, not a dramatic one. Most frameworks already send compact JSON by default anyway.

Myth 2: "So minifying is pointless"

Also wrong. Compression doesn't happen everywhere, and some limits apply to the raw size:

  • Data stored at rest. JSON in a database column, a Redis key, localStorage or a message queue is usually stored uncompressed. A 37% saving there adds up across millions of rows.
  • Size limits on raw bytes. Cookies (about 4 KB), URL query strings, environment variables, CI secrets and many queue message limits all count uncompressed characters.
  • Embedded config. JSON pasted into an HTML data- attribute, an inline <script type="application/json"> block or a single-line .env value has to be compact. Line breaks often aren't allowed at all.
  • Logs. Structured logs are expected to be one JSON object per line. Pretty-printed JSON breaks line-based log tools.

Myth 3: "Minifying can change my data"

Minifying whitespace alone can't change the data. This minifier, though, works by parsing the JSON and printing it back compactly (JSON.stringify(JSON.parse(input))), which brings a few edge cases you should know about:

{
  "price": 1.5,
  "big": 12345678901234567890,
  "e": 1e3,
  "u": "รฉ",
  "dup": 1,
  "dup": 2
}

minifies to

{ "price": 1.5, "big": 12345678901234567000, "e": 1000, "u": "รฉ", "dup": 2 }
  • 1.50 โ†’ 1.5 and 1E3 โ†’ 1000: same value, different text.
  • รฉ โ†’ รฉ: the same character, written literally instead of escaped.
  • 12345678901234567890 โ†’ 12345678901234567000: precision loss. JavaScript numbers are 64-bit floats and can't represent integers beyond 2^53 exactly. If your data has 64-bit IDs as bare numbers, keep them as strings.
  • The duplicate key dup keeps only its last value.

For ordinary data these don't matter, and the minified output parses back to the same values your application would see. Any other JavaScript consumer reading the original would hit the same number limits.

Myth 4: "Minifying also validates and fixes my JSON"

It validates. It doesn't fix. Because the input is parsed first, invalid JSON is rejected with the error and its line and column, and the minifier won't guess at a repair. If you get an error, run the text through the JSON Validator, fix it, then minify.

How to minify JSON in the browser

  1. Open the JSON Minifier and paste your formatted JSON into JSON input. Click Load sample to try a short example.
  2. The Minified JSON output updates as you type. There's no button to press.
  3. Copy the result, or download it as output.json.

The sample document shows the effect at a small scale: 171 characters pretty-printed, 122 minified, about 29% smaller. Everything runs locally, so it's fine to paste config containing internal hostnames or keys.

When should you not minify?

  • Files people edit. Keep package.json, configs and fixtures in version control readable. Minified JSON in Git produces one-line diffs nobody can review.
  • Debug output. If a person will read it, pretty-print it with the JSON Formatter.
  • When a different format would save more. If size really matters, shorter key names, removing null fields, or a binary format will save far more than whitespace.

FAQ

Is minified JSON slower or faster to parse?

Slightly faster, since the parser reads fewer bytes, but the difference is tiny next to network time and the work of building objects. Choose based on size and readability, not parse speed.

Can I put minified JSON inside a string?

Yes, but it has to be escaped for the host format. Inside another JSON string, every " becomes \". In a URL, run it through a URL encoder. Minifying first keeps the escaped result shorter.

Does minifying remove comments?

Standard JSON doesn't allow comments, so input with // or /* */ fails to parse rather than having them stripped. Remove them first, or keep JSONC files in their original form.

Shrink your next payload with the JSON Minifier.