HTML Formatterhtmlformatteronline.com

JSON minifier

Strip every byte JSON does not need. Lossless for your data, and the size readout tells you exactly what you saved.

Your JSON 0 lines
Minify
Minified 0 lines
Paste JSON on the left, then press the button.

What minified JSON is for

Formatting adds one newline and several spaces per key. On a deeply nested document that is 30 to 50 percent of the file. Minified JSON is the same data with none of it — the form you want on the wire, in a cache, in a database column or inside a data attribute.

The saving is real but, as with HTML, smaller than the raw numbers suggest once compression is involved. Gzip handles repeated whitespace extremely well. Minify anyway when it is free, which in an API response it always is.

When it genuinely matters

API responses. Most frameworks pretty-print JSON in development and forget to stop in production. Check yours: JSON.stringify(data) with no third argument is the minified form.

Values inside another format. JSON-LD in a <script> tag, a config string in an environment variable, a payload inside a data- attribute. Minifying keeps these from becoming unreadable walls of indentation inside the host document.

Storage and cache keys. Redis values, localStorage, database text columns. Whitespace there costs you on every read as well as every write.

Message size limits. Webhooks, queue messages and serverless payloads often cap at 256 KB or 1 MB. Minifying is the cheapest way under the line.

It is lossless, with one caveat

Minifying JSON is genuinely lossless for data, because JSON has no significant whitespace anywhere outside of string values — and string values are never touched. Run the output through the formatter and you get your document back.

The caveat is numeric normalisation, which applies to formatting too. Because the document is parsed and re-serialised, 1.50 becomes 1.5, 1e3 becomes 1000, and a number with more than about 17 significant digits loses precision — that last one is a limitation of every JSON parser in every language, not of this tool. If you have identifiers long enough to hit it, they should be strings.

Before — 214 bytes
{
  "sku": "A-100",
  "title": "Linen shirt",
  "price": 58,
  "tags": ["new", "cotton"],
  "stock": { "s": 4, "m": 0, "l": 12 }
}
After — 98 bytes
{"sku":"A-100","title":"Linen shirt","price":58,"tags":["new","cotton"],"stock":{"s":4,"m":0,"l":12}}

Doing it in code instead

For anything repeatable, minify in your own stack rather than by hand.

JavaScript
JSON.stringify(data)              // minified
JSON.stringify(data, null, 2)     // formatted
Python
import json
json.dumps(data, separators=(",", ":"))   # minified
json.dumps(data, indent=2)                # formatted
Command line
jq -c . input.json > output.json   # minified
jq . input.json                     # formatted

Python's default json.dumps puts a space after every comma and colon, so passing separators is what actually minifies it. It is the most commonly missed of the three.

Questions about this tool

Will minifying break my JSON?

No. The document is parsed and re-serialised, so if it comes out at all it is valid. Whitespace inside string values is preserved exactly — only the whitespace between tokens goes.

How much smaller will it get?

Typically 20 to 50 percent of the raw bytes, depending on how deeply nested the document is and how short the keys are. A file that is mostly long string values shrinks least, because the strings are untouched. After gzip the difference is a few percent.

Can I get the formatting back?

Yes — the formatter rebuilds it from the parsed structure. Nothing meaningful is lost, since JSON has no comments to strip in the first place.

Should I minify JSON I keep in version control?

No. A minified file has no useful diff, so every change looks like the whole file changed. Keep the formatted version in the repository and minify on the way out.

Related tools

Learn the why, not just the how

Longer reading on formatting, indentation and minification.