What is JSON minification?
Minifying JSON removes the spaces, tabs and line breaks between values, so the same data takes up fewer bytes. Whitespace inside strings is kept, because it is part of the data.
Formatted JSON (98 bytes):
{
"id": 42,
"user": {
"name": "Ada",
"roles": [
"admin",
"dev"
]
}
}
The same data minified (55 bytes), 44% smaller:
{"id":42,"user":{"name":"Ada","roles":["admin","dev"]}}
How to minify JSON
- Paste your JSON into the input, select Open file, or drop a file onto it.
- Select Minify, or press Ctrl + Enter (⌘ + Enter on Mac).
- If there is a syntax error, the message shows its line and column with a suggested fix.
- Select Copy or Download to use the result. The size table shows how much you saved.
How much does minifying save?
It depends on how the JSON was formatted. Deeply nested JSON indented with four spaces can shrink by half; JSON that is already compact barely changes.
Over the network the saving is usually much smaller, because servers compress JSON responses with gzip or Brotli, and compression is very good at squeezing repeated whitespace. That is why this tool shows two numbers: the raw saving and the saving after gzip. If the gzipped saving is a few percent, minifying a compressed API response won't make a noticeable difference.
When to minify JSON
Minify when bytes matter and compression is not available or the JSON is embedded somewhere:
- Storing JSON in environment variables, database columns, cookies or local storage.
- Embedding JSON in HTML, such as
<script type="application/ld+json">ordata-attributes. - Putting JSON in a URL or a command-line argument, where line breaks cause trouble.
- Writing test fixtures or log lines that should fit on one line.
Keep JSON formatted when people read or review it. Configuration files in a Git repository, for example, are easier to edit and produce cleaner diffs when they are indented.
Minifying JSON in code
Most languages can minify JSON in one line, but check how they treat numbers:
// JavaScript: re-serialises the data, which rounds integers above 2^53
JSON.stringify(JSON.parse(text));
# jq
jq -c . data.json
# Python: separators remove the spaces after commas and colons
json.dumps(json.loads(text), separators=(",", ":"))
The JavaScript approach goes through JSON.parse, so a large ID such as 12345678901234567890 comes out as 12345678901234567000. This minifier works on the text itself and keeps every number exactly as written.