JSON Minifier
Removes formatting whitespace only — never a character inside a string.
Which whitespace is safe to remove
JSON allows spaces, tabs, carriage returns and line feeds between tokens, and nowhere else. Whitespace inside a string literal is data and must survive byte-for-byte: minifying {"msg": "a b"} must not collapse the two spaces to one. A correct minifier therefore parses the document and re-serialises it, rather than running a regular expression over the text. Regular-expression minifiers silently corrupt strings that contain //, /* or quote characters.
What minification actually buys you
| Payload | Pretty | Minified | Gzipped pretty |
|---|---|---|---|
| Small API object | ~20% larger | baseline | within 1–3% of minified |
| 1 MB config dump | ~15% larger | baseline | within 1–2% of minified |
| Embedded in a URL or cookie | matters directly | baseline | not applicable — no compression |
| Stored in memory for a cache key | irrelevant | baseline | not applicable |
The pattern is consistent: minification saves real bytes only where compression is unavailable — URLs, cookies, small inlined scripts, and byte-counted storage. Over HTTPS with gzip or Brotli, it is close to a rounding error.
The real reasons to minify
- Fitting a size limit. Cookies are capped at roughly 4 KB per domain, and some APIs reject payloads over a fixed byte count.
- Embedding in a URL. A query parameter carrying a JSON blob must stay short and percent-encoded.
- Comparing for equality. Two documents that differ only in formatting look identical when minified — useful before a hash comparison.
- Reducing log volume. One line per record instead of thirty makes logs greppable and cheap to store.
Minified JSON is not the same as JSON Lines. Minifying an array keeps it one JSON value spanning one long line; JSON Lines is many independent JSON values, one per line, which is what streaming tools actually want. Confusing the two breaks line-based processors.
Round-trip safety
Minification here is done by parsing to a value and re-serialising. That means the output is guaranteed to be valid JSON, and any input that cannot be parsed produces an error instead of a partially-processed string. Two consequences worth knowing: numbers may be re-rendered in a normalised form (1.0 becomes 1, 1e2 may become 100), and duplicate keys collapse to the last value. Both are artefacts of parsing, and both are silently different from the input.
How to use it
- Paste the JSON document.
- Minify.
- Check the reported reduction in bytes and percentage.
- Copy the single-line result.
Worth knowing
- Whitespace inside string literals is data and is preserved exactly.
- Compression already removes most of the benefit over an HTTPS response.
- Numbers may be re-rendered in a normalised form because the document is re-parsed.
- Output is guaranteed parseable, or an error is reported.
Limitations
- Comments cannot be preserved — they are not legal JSON to begin with.
- Duplicate keys collapse to the last value, as parsing dictates.
- Number formatting may change even when the value does not.
- Extremely large documents are limited by tab memory.
Frequently asked questions
Does minifying change my data?
1.0 prints as 1) and duplicate keys, where the last value wins and the earlier ones disappear.Will minifying break my JSON?
How much smaller does it get?
Can I use a regex to minify JSON instead?
// or a quote character, at which point it silently corrupts the document. Parse and re-serialise instead.