Menu

JSON Minifier

Purpose: Strip all whitespace from JSON to shrink payloads for APIs and config files, with size savings shown.

JSON Minifier: How It Works

Minifying JSON strips every character that exists only for human readers — indentation, line breaks, and the spaces around colons and commas. The data is byte-for-byte identical to a parser; the file is typically 15–30% smaller.

What is removed, and what is not

RemovedNever touched
Indentation and line breaksWhitespace inside string values
Space after a colonKey names and their order
Space after a commaEscape sequences
Trailing whitespaceNumeric precision

Whitespace inside a string is data, not formatting. {"note": "two spaces"} keeps both spaces — a minifier that removed them would be corrupting the content.

How much you actually save

DocumentFormattedMinifiedSaved
Small config2.1 KB1.6 KB24%
API response, 100 records48 KB34 KB29%
Deeply nested structure120 KB76 KB37%

Deeply nested documents save most, because each level of indentation multiplies across every line.

The important caveat: minify or compress?

If your server sends Content-Encoding: gzip or br — and it should — most of minification's benefit is already captured. Compression algorithms handle repeated whitespace extremely efficiently. A 48 KB formatted response might compress to 6 KB, while the minified version compresses to 5.4 KB: a further 10% on top of an 87% reduction.

The order of importance is therefore: enable compression first, minify second. Minifying while serving uncompressed is optimising the smaller variable.

When minification still matters

When to keep it formatted

A practical workflow

Keep the formatted version as the source of truth in your repository, and minify as a build or serialisation step. Most languages do this by default — JSON.stringify(obj) without an indent argument produces minified output, and pretty-printing is the option you have to ask for. In practice, this means most APIs are already minified and the decision only arises for files you write by hand.

Verifying a minification

Minification must be lossless. Parse both versions and compare the resulting objects rather than the text — key order can differ without any change in meaning. If a file no longer parses after minification, the original almost certainly contained an unescaped character or an invalid construct that formatting was concealing.

Frequently Asked Questions

Does minifying change my data?
No. It removes only whitespace between tokens. Whitespace inside string values is preserved, because there it is data rather than formatting. A parser sees exactly the same structure.
Should I minify if I already use gzip?
The additional benefit is small — compression already handles repeated whitespace very efficiently. Enable compression first; minification adds perhaps another 10% on top of an already large reduction.
How much smaller does JSON get?
Typically 15–30%, and more for deeply nested documents where indentation accumulates. The exact figure depends on nesting depth and how long your key names are relative to your values.
Should I commit minified JSON to version control?
No. A minified file is a single line, so every change produces an unreadable one-line diff. Keep the formatted version in the repository and minify as a build step.
Can minified JSON be restored?
Yes, completely. Formatting carries no information, so any formatter reconstructs a readable version. The only thing not recoverable is the original indentation style, which does not matter.
Why does my file fail to parse after minifying?
Usually because it was already invalid and the formatting concealed it — an unescaped character or a construct the parser tolerated differently. Validate the original first, then minify.

Related Developer Tools

Browse all Developer tools →