Skip to content
jsonbeautifiers
English

JSON Minifier

Strip every byte of whitespace and see exactly what you saved.

Filter with JSONPath

RFC 9535 syntax. The result replaces the pane you opened this from.

 

Nothing you paste leaves your browser. The connect-src allowlist makes that a browser guarantee rather than a promise. Check it yourself

Minifying removes every byte of whitespace that a parser ignores: the newlines, the indentation, the space after each colon. Nothing else changes, and the parsed result is identical.

On a typical formatted API payload this removes between 10 and 20 per cent of the bytes. On a deeply nested document formatted with four spaces it can be more than a third.

Where it actually helps, and where it does not

Minifying is worth doing for anything stored or transmitted at volume: API responses, config baked into a bundle, records in a queue, rows in a column store.

It is worth much less than people expect over HTTP, because gzip and brotli already compress repeated whitespace extremely well. Minifying a response that is already gzipped typically saves a few per cent, not twenty. Where it does still matter is anywhere compression is not applied: local storage, a database column, a message body with a hard size cap, or a log line.

It is worth nothing at all for a file a human reads. Minified JSON is one enormous line, and every diff on it is a rewrite of the whole file.

What minifying does not do

It does not shorten keys, drop null values, reorder anything or change numbers. Those are transformations of your data, not of its formatting, and a minifier that did them silently would be dangerous.

In particular, numbers keep their exact text. A minifier built on JSON.parse would turn 1.50 into 1.5 and 1e3 into 1000, which is smaller but is also a different document.

How to do this in code

Minifying in code.

js JavaScript
const min = JSON.stringify(JSON.parse(text));

// Note this also normalises numbers: 1.50 becomes 1.5.
py Python

json.dumps defaults to ", " and ": " as separators, so the naive call is not actually minified.

import json

# The separators argument is the part people miss: without it
# Python leaves a space after every comma and colon.
min_text = json.dumps(json.loads(text), separators=(',', ':'))
sh jq
jq -c . input.json > output.min.json
go Go
var buf bytes.Buffer
if err := json.Compact(&buf, data); err != nil {
    return err
}
// Compact works on bytes, so numbers are untouched.

Questions

How much will I actually save?
The tool shows the before and after byte count for your specific document. As a rule of thumb, two-space formatted JSON is 10 to 20 per cent whitespace, and four-space is more. Over a gzipped connection the real-world saving is far smaller, because compression already handles repetition well.
Is minified JSON still valid?
Yes. Whitespace between tokens is insignificant, so minified and formatted documents parse to exactly the same value.
Should I minify JSON in my repository?
No. Version control is for humans reading diffs, and a minified file makes every change look like a full rewrite. Minify at build or send time.