Ask how much smaller a JSON file gets when you minify it and you will hear confident guesses: a third, a half, almost nothing. Every guess can be right, because the answer is not a property of JSON. It is a property of how the file happened to be formatted before you touched it. Minification removes whitespace and nothing else, so the saving was decided the moment the file was written, by whoever chose its indentation.
This guide works through the arithmetic on a measured example, explains why two files holding identical data report completely different percentages, and shows how to measure your own file with the free JSON Minifier on Ovatly, which reports the exact bytes saved.
Contents
- Quick answer
- What minification actually removes
- The general law: the saving belongs to the formatting
- Why the percentage is counted in bytes, not characters
- How to measure your own file, step by step
- Worked example: 38 bytes in, 29 bytes out
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Minifying JSON removes whitespace only: the indentation, line breaks and spaces between tokens. Values, key names and key order are preserved exactly, and the output parses to exactly the same value as the input. In the worked example below, a pretty printed input of 38 bytes minifies to 29 bytes, a saving of 23.7 percent, and every saved byte is a whitespace character. A deeply indented file can give up a larger share; an API response that already arrives on one line saves 0 percent. Both results are correct. Paste your JSON into the JSON Minifier and it reports the bytes saved, so you never have to guess.
What minification actually removes
JSON parsers ignore the whitespace between tokens: the spaces starting an indented line, the newline after each entry, the space after a colon or comma. None of it changes the value. That formatting layer is all a minifier strips.
Whitespace inside a string value is different: a space inside "name": "Ana Maria" is part of the data, and because values are preserved exactly, it stays. The reach of minification is precise: everything between tokens can go, everything inside values cannot. That is why the saving is knowable in advance: count the formatting characters and you have counted what minification will save.
The general law: the saving belongs to the formatting
Take two files holding the same records. The first was written by a person, or exported by a tool that pretty prints: one key per line, a wide indent, a space after every colon, so a large share of its bytes are formatting. The share grows with depth, because every nesting level adds its indentation to every line inside it, so a small, deeply nested file can be surprisingly heavy for the data it carries.
The second file came straight from an API that already serves compact JSON: one line, no indentation, no optional spaces. There is nothing to remove, and the minifier reports a saving of 0 percent. That is not the tool failing; it is the tool reporting, accurately, that the file is already as small as whitespace removal makes it.
So the percentage is a measurement of the input's formatting habits, not of the data and not of the tool. Comparing percentages between two different files tells you which one was formatted more generously, and nothing more.
Why the percentage is counted in bytes, not characters
The minifier measures size in UTF-8 bytes, the unit files are actually stored and sent in. For plain ASCII text, bytes and characters are the same number. They part company as soon as the data contains non-ASCII characters: an accented letter takes two bytes, others take three or four.
Whitespace is always plain ASCII, one byte per character. So in a text-heavy file full of accented names, the total byte count grows while the removable whitespace stays the same, and the reported percentage comes out smaller than a character count suggests. The percentage is honest about bytes, and bytes are what you pay for in storage and transfer.
How to measure your own file, step by step
- Open the JSON Minifier. It runs locally in your browser, and nothing you paste is uploaded.
- Paste your JSON exactly as it stands, formatting and all: the measurement only means something for the real file.
- Run the minifier. It reports the original size, the minified size and the bytes saved, alongside the minified output.
- Read the percentage against the input's formatting, not against a fixed expectation. Copy the minified output where it is needed, and keep the pretty original as the copy you edit.
Worked example: 38 bytes in, 29 bytes out
Here is a small pretty printed input:
{
"name": "Ovatly",
"tools": 250
}
It measures 38 bytes. Minified, it becomes:
{"name":"Ovatly","tools":250}
That is 29 bytes. The saving is 9 bytes, and 9 out of 38 is 23.7 percent.
Count where those 9 bytes were. Three are newlines: one after the opening brace and one after each of the two entries. Four are spaces of indentation, two before each key. Two are the spaces after the two colons. That is the whole saving, accounted for character by character. Not one byte of data moved: the keys, the string, the number and their order are identical in both versions, and any parser reads both texts as the same value.
Now scale the thought up. A configuration file with fifty keys across three levels of nesting carries hundreds of these characters, and its percentage will be higher than 23.7. A response body written by a server with no formatting carries none of them, and its percentage will be zero.
Limitations and honest tradeoffs
Minification cannot shrink the data itself. Long key names, repeated structure and the contents of strings all stay, byte for byte. If a file is large because of what it says, rather than how it is formatted, minification will barely touch it, and the honest fix is to send less data.
If the input is not valid JSON, the tool reports the parse error and produces no partial output, so a broken file gives you an error rather than a quietly truncated result. And the output is a tradeoff: a minified file is one dense line, painful to read, search or edit. Minify the copy you send; keep the pretty version as the one you work on.
Common mistakes
- Expecting a fixed percentage. There is none. The saving equals the whitespace the input happened to contain.
- Reading 0 percent as a failure. It means the input was already compact, which is a finding, not an error.
- Comparing percentages across different files. The number describes each file's own formatting, so the comparison measures formatting habits, not quality.
- Counting characters instead of bytes. On non-ASCII text the two counts differ, and bytes are what storage and transfer charge for.
- Minifying your only copy. The one-line result is miserable to edit. Keep the pretty original; minify a copy each time.
FAQs
How much smaller does minifying a typical JSON file make it? There is no typical figure, because the saving equals the whitespace in the input. The worked example in this guide goes from 38 bytes to 29 bytes, a saving of 23.7 percent. A deeply indented configuration file can save more, and an API response that already arrives on one line saves nothing at all.
Why did the minifier report 0 percent saved? Because the input was already compact. If the JSON has no indentation, no line breaks and no spaces after colons or commas, there is no whitespace to remove, so 0 percent is the correct result, not an error.
Does minifying JSON change my data? No. Values, key names and key order are preserved exactly, and the minified output parses to exactly the same value as the input. Only the whitespace between tokens is removed.
Why is the percentage smaller than I expected on a text-heavy file? The tool measures size in UTF-8 bytes. Whitespace characters are one byte each, but non-ASCII characters such as accented letters count as two or more bytes. That inflates the total size without adding anything removable, so the percentage saved looks smaller than a character count would suggest.
Is my JSON uploaded to a server? No. The minifier runs in your browser and the JSON never leaves your device, so you can measure and minify payloads and configuration files without sending their contents anywhere.
Conclusion
The size a JSON file loses to minification is exactly the whitespace it was carrying: 9 bytes out of 38 in the worked example, nothing at all in a file that was already compact. Measure your own file with the JSON Minifier instead of guessing, and read the percentage as a fact about the input's formatting. If you are deciding which form a file should live in, our companion guide on minified vs pretty printed JSON gives the decision rule, and the Data and JSON Tools guides cover the rest of this series.
References
- RFC 8259, the JSON data interchange standard, which defines where insignificant whitespace may appear: https://www.rfc-editor.org/rfc/rfc8259
- MDN Web Docs, on JSON syntax and how parsers read it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON