Minify JSON

Strip every space, newline and indent from a JSON document, and see how many bytes that saved. It validates as it minifies, so invalid JSON is reported rather than silently mangled. Nothing you paste leaves your browser.

How do I minify a JSON file?

Changes whitespace only: number spelling, key order, duplicate keys and string escapes are preserved. Duplicate keys remain ambiguous to downstream readers. Limit: 5 million characters.

What minifying JSON does, and what it is worth

Minifying JSON removes every character that a parser does not need: the newlines, the indentation, and the space after each colon and comma. The data is identical afterwards — same keys, same values, same order, same structure — because whitespace between tokens carries no meaning in JSON. What changes is the size, and on a heavily indented document that is a larger difference than people expect. A two-space-indented config file commonly loses 20 to 30% of its bytes, and a deeply nested API response can lose more.

When it is worth doing

The clear cases are anything crossing a network repeatedly or being stored at volume: API responses, config bundled into a web page, documents in a cache, payloads in a message queue. Over a lot of requests, whitespace is real bandwidth. It also matters against a hard limit — a field with a maximum length, a URL parameter, a message size cap — where minifying is sometimes the difference between fitting and not.

The case where it is not worth doing is a file a person reads or edits. A minified config file is genuinely hostile to work with, and version control makes it worse: a one-line document produces a diff of the entire line for any change, so review becomes impossible. Keep the readable version in the repository and minify as a build step, not as an edit.

Gzip does most of this already

It is worth being honest about the size gain. Any server worth using compresses responses with gzip or brotli, and repeated whitespace is exactly what those algorithms are best at. After compression, the difference between minified and formatted JSON is often small — sometimes only a few percent. Minifying still helps, and it helps most where compression is not in play: data stored in a database column, embedded in another document, or held in a size-limited field.

Formatting is the opposite operation

To go the other way and make a document readable, the JSON formatter and validator indents it and shows you exactly where it breaks if it will not parse. The two live on separate pages deliberately: they answer opposite needs, and a page trying to do both serves neither well. Both run in your browser, which matters given how often the JSON people need to inspect is a live API response carrying tokens or customer records.

Next steps

Related tools

What to do with the result

Browse all developer utilities, or see every QuickMerge tool.

Frequently asked questions