Skip to content
toolbelt
Back to Guides

When Minifying JSON Actually Helps

By ·

Updated

Removing whitespace saves bytes, but it is rarely the win people hope for. Here is the honest maths and when to bother.

What is this tool?

Minifying strips the indentation and newlines from JSON. The data is identical; only the layout goes. It is the formatter running backwards.

How it works

Parse, then re-print with no spacing. I show you the before and after character counts so you can see whether it was worth it. That comparison is the point — sometimes the saving is 3 percent and you should not care.

Example

Pretty: 148 characters
Minified: 92 characters
Saving: 38%

Pretty:
{
  "enabled": true,
  "retries": 3
}

Minified:
{"enabled":true,"retries":3}

When to use it

When you are storing JSON in a URL, a cookie, or a column that has a length limit. When you are shipping a static config file and saving bytes matters. Not when you are debugging — minified JSON is unreadable by design.

Optimization Tips

If you are minifying to fix page weight, look at gzip first. Indentation compresses almost perfectly, so a pretty-printed file gzips to nearly the same size as a minified one. Minifying matters for uncompressed transport, not for CDN-cached responses.

Frequently Asked Questions

Does minifying break anything?
No. Any parser that reads the pretty version reads the minified one. The values are identical.
Should I commit minified JSON?
Please do not. Commit the readable version and minify at build time. Future you will spend a day trying to read a diff of one long line.
Is there a safer gain?
Yes: remove keys you do not use, rather than removing the spaces between them.
Why is my saving only a few percent?
Deeply nested data has proportionally more content than indentation, so the whitespace is a smaller share. That is normal.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools