Minify JSON: What It Does and When to Use It
· 2 min read
Minifying JSON removes the whitespace between values. It takes formatted JSON, with its indentation and line breaks, and returns the same data on one line.
The JSON Minifier does this in your browser. This guide explains what changes, what stays the same, and when minifying helps.
What minifying does
Minifying removes the spaces, tabs and line breaks between values. That whitespace has no meaning in JSON, so minified JSON parses to exactly the same data. Only the text changes.
Formatted:
{
"name": "Ada Lovelace",
"languages": ["en", "fr"],
"active": true
}
Minified:
{"name":"Ada Lovelace","languages":["en","fr"],"active":true}
The space inside "Ada Lovelace" stays: spaces inside strings are data.
What does not change
- Strings keep their contents, including spaces.
- Numbers keep their values, and integers too large for JavaScript are not rounded.
- Keys keep their order, unless you ask for them to be sorted.
When to minify
Minify when one compact line is more useful than a readable layout:
- Storing JSON in a database column or an environment variable.
- Sending smaller payloads.
- Putting JSON on one line, such as in a log entry or a test fixture.
When not to minify
Don't minify files people read and edit, such as config files in a repository. Diffs and code review are much easier with formatted JSON, because each value sits on its own line.
Minifying API responses also saves less than it seems. Servers usually compress responses with gzip or Brotli, which already removes most of the size cost of whitespace.
Sort keys for stable output
With Sort keys A to Z ticked, the same data always gives the same output, whatever the original key order. That makes minified JSON easier to compare, hash or cache. Arrays keep their order, because order matters in arrays.
Going back and comparing
Paste minified JSON into the JSON Formatter to indent it again. Formatting and minifying are exact opposites, so you can move between the two without losing anything.
To check whether two documents hold the same data, use JSON Compare. It ignores formatting and key order, so you don't need to minify or sort first.
Try it
Paste your JSON into the JSON Minifier and copy the result. It runs in the browser tab, so nothing is sent to a server, logged or stored.