Skip to main content
CuteJSON
↑↓ Navigate Enter Select Esc Close

How to minify JSON and see exactly what it saved

Published 2 min read By Akash Kinkar Pandey

Minifying JSON means removing the whitespace it does not need: the spaces after colons and commas, the indentation, and the line breaks. That is the whole operation. Nothing about the values, their order, or their meaning changes.

Using the JSON minifier

Paste your document, or load the sample, and press Minify. The result appears on the right along with the byte count, so you can see the actual saving rather than guess at it. A typical indented config file shrinks by 30 to 50 percent depending on how deeply it is nested and how long the key names are.

Why format and minify are safe to alternate

Both tools on this site work the same way under the hood: tokenize the input, validate it, and reprint from the token stream rather than from a value parsed by JSON.parse. That means a long integer keeps every digit and an object key that looks like a number keeps the position you wrote it in, whichever direction you go. You can format a document, then minify it, then format it again, and the values never drift.

That matters because the common alternative, going through JSON.parse and JSON.stringify, silently rounds integers past Number.MAX_SAFE_INTEGER and reorders integer-like keys. A minifier built that way is quietly lossy on exactly the documents where losing a digit matters most: database IDs, timestamps, external identifiers.

When minifying actually helps

Minified JSON is for machines, not for the next person who has to read the file. It is worth doing before sending a document over a network where every byte has a cost, such as embedding a config blob in a URL, storing it in a database column with a size limit, or shipping it inside a mobile app bundle. It is not worth doing to a file you are about to commit to version control, since a minified diff is unreadable and a formatted one is not.

A quick way to tell if minifying broke something

If you minify a document and then decide to check it, format it right back. Since both directions reprint from the same token stream, the formatted result should be byte for byte identical to what you started with, aside from any trailing whitespace you had. If it is not, something upstream of this tool already changed the data, which is worth knowing before you ship it.

Back to all posts