JSON Minifier
Remove whitespace from JSON and see exactly how much smaller the payload becomes.
Processed on your device — no upload
How to use it
- Paste the formatted JSON.
- Read the before-and-after sizes.
- Copy the minified result.
How it works
Minifying is a parse followed by a re-serialisation with no indentation. That sounds like a roundabout way to remove spaces, and the alternative is why it is done this way.
Stripping whitespace with a pattern match corrupts the data. A regular expression that removes spaces cannot tell the space in { "a": 1 } from the space in {"name": "Sara Haddad"}. Parsing removes the first kind and cannot touch the second, because by then the string is a value rather than text.
It also means invalid JSON is rejected rather than silently mangled. A minifier that works by pattern matching will happily produce output from a broken file, and the breakage only surfaces later.
The saving is typically 15–30% for indented JSON, and rather less than people expect — because on the wire it is followed by gzip or brotli compression, which is very good at removing repeated whitespace anyway.
A worked example
You are embedding a configuration object into a page and want it as small as possible. Press Load a sample: 340 bytes formatted, 232 minified, a saving of about 32%.
Now the caveat worth knowing before optimising for it. Served over HTTP with gzip, that same file compresses to roughly the same size whether it was minified or not — repeated runs of spaces are exactly what compression algorithms remove first. Minifying JSON that will be gzipped saves a handful of bytes, not a third.
Where it genuinely helps: JSON embedded in an HTML attribute or a data URI, stored in a database column, sent over a connection with no compression, or held in localStorage, which has a hard size limit measured in the raw string.
The safety point in practice. Paste {"greeting": "hello world"} with three spaces inside the string. The minified output still has three spaces. They are data. A regex-based minifier would collapse them and change the value.
To go the other way, the formatter expands it again and reports the exact position of any syntax error.
Questions
How do I make JSON compact for an API?
Minifying strips every space and newline the parser ignores. Worth doing for a payload embedded in a page or stored in a column where the raw size is what counts.
Is my JSON uploaded?
No. It is parsed and re-serialised in your browser, so payloads containing tokens or personal data stay on your device.
Will minifying change my data?
No. Whitespace between tokens is removed; whitespace inside string values is preserved, because the file is parsed rather than pattern-matched.
How much smaller will it get?
Typically 15–30% for indented JSON. Deeply nested files with short values save the most, since indentation is a larger share of the total.
Is it worth minifying if my server uses gzip?
Barely. Compression removes repeated whitespace very effectively, so the gzipped sizes are close. Minify for embedded JSON, database columns and localStorage, where the raw size is what counts.
Can I minify invalid JSON?
No, deliberately. The file is parsed first, so a broken file is reported rather than turned into a smaller broken file.
Does it remove comments?
Comments are not valid JSON, so a file containing them will not parse at all. Strip them before minifying.
Does key order change?
No. Keys stay in the order they appeared.
Is there a size limit?
No fixed limit, though very large files make the text boxes themselves slow to scroll.