Skip to main content

JSON Minifier

Smallest possible JSON, with the savings measured.

Minifying removes every space, tab and newline that a parser ignores. For payloads sent over the wire that is free bandwidth: a formatted document is often 20–40% larger than the same data minified.

Input JSON

Size: 0 BLines: 0

Minified JSON

Paste valid JSON to see the output.
Size: 0 BLines: 0

What actually gets removed

Only whitespace that a parser ignores: the spaces, tabs and newlines between tokens. Whitespace *inside* a string is data and is never touched — "New York" keeps its space, and a string containing a newline keeps it too.

Everything else stays. Minifying does not shorten keys, drop nulls, remove empty objects or reorder anything, and the result is ordinary, fully valid JSON that any parser reads identically to the original.

{
  "id": 1,
  "name": "New York",
  "tags": []
}

{"id":1,"name":"New York","tags":[]}

How much you save

The saving depends entirely on the shape of the document, not its size. Whitespace scales with the number of lines and the depth of nesting, so a deeply nested document with short values is mostly whitespace, while a flat document with long strings is barely affected.

DocumentPrettyMinifiedSaved
500 records, 6 fields each92,864 B51,356 B44.7%
25 records, 6 fields each4,542 B2,459 B45.9%
One tiny 6-level-deep object127 B37 B70.9%

Forty-odd percent is typical for record-shaped data at two-space indentation, and it rises sharply with indentation width — the same document at four spaces is 58% whitespace. Those are real measurements, not estimates; the page shows you the exact numbers for your own document.

What happens after compression

This is the part most minification advice leaves out, and it changes the decision completely. Almost every HTTP response is already compressed with gzip or brotli — and repeated whitespace is the single most compressible thing there is. By the time your JSON reaches the wire, the compressor has removed most of what minifying would have removed.

500-record responseRawGzipped
Pretty-printed92,864 B5,915 B
Minified51,356 B5,718 B
Saving from minifying44.7%3.3%

That does not make minifying pointless — it relocates the benefit. It still matters where compression is absent or where raw size is what counts: rows in a database column, values in localStorage, documents in a queue message with a hard size cap, log lines, or an embedded device with no gzip at all. Check that your server has compression enabled first; if it does not, that is worth far more than minifying.

What minifying will not fix

AssumptionReality
It removes nullsNo. "note": null survives. Remove them in the code that builds the payload if you do not want them.
It removes empty arrays and objectsNo. [] and {} stay.
It shortens keysNo. Long key names repeated across 10,000 records are usually the real cost — and gzip handles them very well.
It makes parsing fasterMarginally, and rarely measurably. Parse time tracks the number of values, not the whitespace.
It is a security measureNo. Minified JSON is trivially re-formatted. Anything sensitive in the payload is still there.

Minifying is re-serialization too

The document is parsed and written out again, which means it normalises the same things formatting does. Worth knowing before you minify a file you intend to keep:

  • 1.0 becomes 1, and 1e3 becomes 1000.
  • "\u0041" becomes "A".
  • Duplicate keys collapse — the last one wins and the others are gone.
  • Integers beyond 2^53 lose precision, silently.

The operation is otherwise lossless and reversible: run the output through the beautifier and you get a readable document back. What you cannot recover is the original indentation style, because that information no longer exists anywhere.

Minifying in a build or a pipeline

For anything repeatable, do this at the command line rather than by hand. jq -c is the standard answer and it is already installed on most machines.

# One file, in place
jq -c . input.json > output.json

# Every JSON file in a directory
find . -name '*.json' -exec sh -c 'jq -c . "$1" > "$1.min"' _ {} ;

# Convert a formatted array into NDJSON — one record per line
jq -c '.[]' records.json > records.ndjson

# In Node, with no dependencies
node -e 'process.stdout.write(JSON.stringify(require("./input.json")))'

That third command is worth knowing. NDJSON — one minified document per line — is what log pipelines, BigQuery, and most streaming loaders actually want, and it is strictly better than a single giant array for anything processed record by record, because a consumer can read one line at a time instead of parsing the whole file into memory.

When not to minify

  • Files in a repository. A minified file is one enormous line. Every change shows as the whole file changed, code review becomes impossible, and merge conflicts are unresolvable.
  • Configuration people edit. Readability is the entire point.
  • Anything you are debugging. Minify last, if at all.
  • Responses served with compression, unless you have measured and the numbers justify it.

The reasonable default is to store and commit formatted JSON, minify at the point of transmission or storage if measurement says it helps, and never minify anything a person is expected to read.

Frequently asked questions

How much smaller will my JSON get?
Typically 40–50% for record-shaped data at two-space indentation, and more for deeply nested documents. The page measures your actual document and shows the exact byte counts rather than an estimate.
Is minifying still worth it if my server uses gzip?
Usually much less than you would expect. On a 500-record payload, minifying cut the raw size by 44.7% and the gzipped size by 3.3% — compression removes repeated whitespace very effectively on its own. It still matters for uncompressed storage, size-capped messages and embedded targets.
Can I undo minification?
Yes — the data is unchanged, so the beautifier restores a readable layout immediately. The original indentation style is not recoverable, because it is not stored anywhere.
Does minifying remove null values or empty objects?
No. Only insignificant whitespace is removed. null, [] and {} all survive — filter them out where the payload is built if you do not want them.
Is minified JSON still valid JSON?
Completely. Whitespace between tokens is optional in the JSON grammar, so every parser reads the minified document exactly as it read the original.
Does minifying change whitespace inside my strings?
No. Whitespace inside a string is part of the value. Only the spacing between tokens is removed.