Developer Formatting

JSON minifier

What to do

Processed in your browser · nothing is uploaded

Local · whitespace inside strings is kept
Advertisement
320 × 100

Removes every space and line break outside strings. On a formatted document that is typically a 15 to 30 percent reduction before any compression.

How to use the json minifier

1 Paste the formatted JSON.
2 Every space and line break outside a string is removed.
3 Switch to Format to expand it again; the data is identical either way.
4 Copy the result, or save it as a file.

Whether that saving is worth anything depends on whether the response is gzipped, and it usually is. Gzip compresses repeated whitespace extremely well, so minified and formatted JSON often land within a few percent of each other over the wire. Where minifying genuinely helps is anywhere compression is not applied: data in a database column, embedded in a page as a string, put in a cookie or a header, or written to a file that is read back directly. For an ordinary HTTP API, turning compression on is worth far more.

The size of the win depends entirely on the shape of the document. The four-line sample above is 30 bytes formatted and 19 minified, because it is almost all indentation. A flat document of long string values barely moves, since strings are never touched. Deep nesting with short values is where minifying earns its keep.

It is worth being clear about what minifying is not. It does not shorten keys, deduplicate repeated strings or pack anything more tightly: a payload that repeats "customerReference" ten thousand times still repeats it. Those wins come from the code that produces the JSON, or from a binary format such as MessagePack, and no amount of whitespace removal substitutes for them.

One consequence of how this works: the document is parsed and written out again rather than scanned for spaces, so numbers are normalised on the way through. 1.0 comes back as 1 and 1e3 as 1000, which is the same value. An integer beyond 9007199254740991 does not survive intact, which is not a quirk of this tool but of every JavaScript consumer your JSON will meet, and the reason large IDs belong in strings.

Questions

15 to 30 percent typically. Over a gzipped connection the real-world saving is much smaller.

ECMA-404; the JSON data interchange syntaxMDN, JSON.parse()
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding