← All blog posts

JSON Minifier vs doing it by hand — which is faster?

WhiteUI · A plain-English guide to the JSON Minifier

For a tiny piece of JSON, removing the spaces by hand feels fast enough. For a real file, with nesting, lists and long values, the JSON Minifier is faster and far less likely to slip. The honest answer is to use your eye for a rough guess and the tool for the real thing, and the comparison below shows why, with the exact byte counts.

At a glance

Three users: 114 of 251 bytes savedSaved 114 bytesKept 137 bytes251 → 137 bytes · 45.4% smaller
Minifying a file with three users saves 114 of 251 bytes: the result is 137 bytes, which is 45.4 percent smaller.

By hand: the easy cases

If your file is one line already, or only two items, doing it by hand takes seconds: delete the line breaks, delete the indenting, and you are done. The tool’s own example is like that: a on one line and b on the next, 22 bytes in total, and removing the spaces by hand gives {"a":1,"b":2}, which is 13 bytes, saving 9 bytes. There is nothing to calculate and nothing to get wrong, because there are only two values and two line breaks to remove.

By hand: the slow cases

Try a file with three users, each with an id, a name and an active flag, plus a count at the end, written with two-space indenting across twenty-three lines. That file is 251 bytes, and the minified result is 137 bytes, so 114 bytes are saved, or 45.4 percent. Doing that by hand means deleting every line break and every indenting space, one at a time, across twenty-three lines, while leaving the spaces inside the names exactly as they are. That is more than a hundred small deletions, and a single slip, such as deleting a space inside a name or leaving a space after a comma, gives a result that looks right but is not the true minified form.

A second comparison: a nested order

Now try a nested order by hand: an order number, a customer block with a name and an email address, and a list of two items with codes, quantities and prices, plus a total. That file is 282 bytes, and the minified result is 175 bytes, saving 107 bytes, or 37.9 percent. By hand you would also have to rewrite the numbers: the price written as 149.50 becomes 149.5, and the total written as 597.00 becomes 597. Those are easy to forget, and a hand-minified file that keeps 149.50 is 2 bytes longer than the true minified result. With the tool you paste once and read the answer, with the numbers already rewritten.

When the tool wins outright

Use the tool when the file has more than a few lines, when it is nested, or when the result has to fit a size limit exactly, because the tool counts the bytes for you. The byte count matters: a file that must fit under a limit needs an exact number, not an estimate, and the tool reports the original size, the minified size and the saving on every run. Use your hand only when the file is two or three lines long and you can see the whole of it at once. The dividing line is simple: if you have to scroll to see the whole file, use the tool.

The common mistake

People minify by hand, delete a space inside a string, and then spend an hour working out why a program rejects the file. A note reading "keep these spaces" has two spaces after keep and three after these, and deleting one of them changes the value, even though the file still looks like valid JSON. The tool never touches the inside of a string: the same file goes from 64 bytes to 55 bytes with the note untouched. If a hand-minified file behaves differently from the original, check the strings first, because that is where a hand edit usually does its damage.

Frequently asked questions

Is it faster to minify JSON with the tool or by hand?

With the tool for anything over a few lines. A three-user file goes from 251 to 137 bytes in one paste, against more than a hundred small deletions by hand.

How much does the tool save on a three-user file?

114 bytes: from 251 bytes down to 137 bytes, which is 45.4 percent smaller.

What does the tool do that hand-minifying often misses?

It rewrites numbers in their shortest form, such as 149.50 to 149.5 and 597.00 to 597, and it counts the exact byte sizes for you.

When is minifying by hand fine?

When the file is two or three lines long and you can see all of it at once. If you have to scroll to see the whole file, use the tool.

More guides on the JSON Minifier

Try it yourself

Try the JSON Minifier — free, in your browser.

Open the JSON Minifier