JSON Minifier explained with worked examples
The JSON Minifier does one job, and it does it the same way every time: it reads your JSON, then writes it back with no line breaks, no indenting and no spaces outside strings. Nothing about the data changes, so the result is safe to use anywhere the original was safe. Four worked examples below show what that means in practice, from a two-item object up to a nested order, with the exact byte counts for each.
At a glance
Example 1: the smallest possible case
Start with the tool’s own example, written across five lines with two-space indenting: an object with a set to 1 and b set to 2. That file is 22 bytes. The minified result is {"a":1,"b":2}, which is 13 bytes. Nine bytes saved, from a file of 22, which is 40.9 percent. The saving is a big share here because a tiny file is mostly spacing: two line breaks, four spaces of indenting and the spaces after the colons add up to more than the data itself.
Example 2: a small profile
Next, a profile with four fields: a name, Priya Sharma, an age of 28, a city, Pune, and a subscribed flag set to true, written with two-space indenting across seven lines. That file is 81 bytes, and the minified result is 64 bytes, so 17 bytes are saved, or 21.0 percent. The share is smaller than in the first example, because the values themselves, especially the name, now make up more of the file. The longer the values, the smaller the share that spacing takes up.
Example 3: a nested order
Now a realistic file: an order with an order number, a customer block holding a name and an email address, and a list of two items, each with a code, a quantity and a price, plus a total at the end. Written with two-space indenting across twenty-five lines, it is 282 bytes. The minified result is 175 bytes, so 107 bytes are saved, or 37.9 percent. Two extra details show up here: the price written as 149.50 comes out as 149.5, and the total written as 597.00 comes out as 597. The numbers are the same values, only written in their shortest form, which is part of why the saving is large.
Example 4: spaces inside strings are kept
Minifying never touches the inside of a quoted string, because the spaces there are part of the value. Take a small file with a message, "hello world", and a note, "keep these spaces", with two spaces after keep and three after these. The file is 64 bytes, and the minified result is 55 bytes, saving 9 bytes, or 14.1 percent. The double and triple spaces inside the note are still there in the result, exactly as typed, while the spaces around the colons and the line breaks are gone. That is the whole rule in one example: spacing between values goes, spacing inside values stays.
Why the saving changes from file to file
Three things decide how much you save. First, the indenting: four-space indenting saves more than two-space indenting, because there are twice as many spaces to remove. Second, the nesting: a file with lists inside objects inside objects has more lines and more indenting than a flat file of the same length. Third, the values: long strings and long numbers are kept in full, so a file full of long values saves a smaller share than a file full of short ones. The tool reports the exact saving for your file, so you never have to guess which of the three is doing the work.
The common mistake
People look at the percentage and think a small percentage means the tool did nothing. A 21.0 percent saving on an 81-byte profile is 17 bytes, and a 37.9 percent saving on a 282-byte order is 107 bytes. The byte count is the number that matters when a file has to fit into a size limit or travel over a slow connection, so read the bytes saved line first and the percentage second.
Frequently asked questions
What does the JSON Minifier actually remove?
Line breaks, indenting and spaces outside strings. The values, including spaces inside quoted strings, are kept exactly as they are.
How much does minifying save on a small file?
The default example goes from 22 to 13 bytes, saving 9 bytes, and a small profile goes from 81 to 64 bytes, saving 17 bytes.
Why did 149.50 become 149.5 in my minified JSON?
The minifier writes numbers in their shortest form. 149.50 and 149.5 are the same value, and 597.00 becomes 597 for the same reason.
Are spaces inside strings removed too?
No. A note reading “keep these spaces” keeps its double and triple spaces, because spaces inside a string are part of the value.
More guides on the JSON Minifier
- How to use the JSON Minifier — step by step
- JSON Minifier formula — how it actually works
- JSON Minifier for beginners — start here
- Common mistakes people make with the JSON Minifier
- JSON Minifier vs doing it by hand — which is faster?
- JSON Minifier — The Complete Guide
- How to get an accurate result from the JSON Minifier
- JSON Minifier for students — with examples
- JSON Minifier for homeowners and DIYers
Try the JSON Minifier — free, in your browser.