Back to NiceJSON
NiceJSON Blog/ How to Minify JSON and When It Actually Helps

How to Minify JSON and When It Actually Helps

Learn what JSON minification does, how much space it saves, how to minify in JavaScript, Python, and the shell, and when gzip makes it matter less.

2 min read
  • json
  • minify
  • performance

What minifying does

Minifying removes everything that humans need but parsers do not: spaces, tabs, and line breaks. The data stays exactly the same.

Before:

{
  "id": 7,
  "name": "Ada",
  "tags": [
    "admin",
    "dev"
  ]
}

After:

{"id":7,"name":"Ada","tags":["admin","dev"]}

How much do you save?

Savings depend on how deeply the original was indented. Heavily nested, pretty-printed JSON often shrinks by 20 to 40 percent. Already compact JSON saves little.

Minify online

  1. Open NiceJSON.
  2. Paste your JSON.
  3. Click Minify.

Copy the single-line result into your config, request body, or fixture.

Minify in code

JavaScript:

const compact = JSON.stringify(JSON.parse(text));

Python:

import json
compact = json.dumps(json.loads(text), separators=(",", ":"))

Command line with jq:

jq -c . input.json > output.min.json

Note that Python's default json.dumps adds a space after commas and colons, so pass separators explicitly to get truly compact output.

Does minifying still matter with gzip?

Most servers compress responses with gzip or Brotli. Compression already removes repeated whitespace very efficiently, so the extra gain from minifying before compressing is small, often a few percent.

ScenarioMinify worth it?
API response behind gzip or BrotliMarginal
JSON stored in a database columnYes, saves storage
JSON embedded in HTML or a URLYes
JSON in a localStorage or cookie limitYes
Config file humans editNo, keep it readable

Rules of thumb

  • Keep source files pretty-printed and readable in version control.
  • Minify at build or transport time, not by hand.
  • If you need to debug a minified payload, paste it into a formatter to expand it again.

Minifying is reversible

Because only whitespace changes, you can always format the JSON again without losing anything. Whitespace inside string values is preserved, so your data is never altered.