← All blog posts

JSON Minifier — The Complete Guide

WhiteUI · A plain-English guide to the JSON Minifier

A one-line result has a surprising number of details behind it: a two-step method, indenting that changes the saving, numbers that get rewritten, strings that are never touched, and byte counts that depend on the characters inside your values. This guide covers them all, so you never have to guess what a number means.

At a glance

Four-space indent: 25 of 89 bytes savedSaved 25 bytesKept 64 bytes89 → 64 bytes · 28.1% smaller
Minifying a profile written with four-space indenting saves 25 of 89 bytes: the result is 64 bytes, which is 28.1 percent smaller.

What it does

The tool takes JSON written for people to read, with line breaks and indenting, and returns the same data on one line. The values do not change, the order of the keys does not change, and the spaces inside quoted strings do not change. The tool opens with an example already filled in: an object with a set to 1 and b set to 2, which is 22 bytes and minifies to 13 bytes, saving 9 bytes, or 40.9 percent.

The method: parse, then stringify

The whole method is one line: minified = JSON.stringify(JSON.parse(input)). First the tool parses your text into data, which is also the check: if the text has a mistake, such as a comma after the last item, parsing fails and the tool reports the error. Then it writes the data back out with no spaces. Because the tool works with data rather than text, the result is always valid JSON, and numbers come out in their shortest form: 149.50 becomes 149.5, and 597.00 becomes 597.

Indenting decides how much you save

The same data saves a different amount depending on how it was indented. A small profile with a name, Priya Sharma, an age of 28, a city, Pune, and a subscribed flag, written with two-space indenting, is 81 bytes and minifies to 64 bytes, saving 17 bytes, or 21.0 percent. The same profile written with four-space indenting is 89 bytes and minifies to the same 64 bytes, saving 25 bytes, or 28.1 percent. The result is identical either way: only the input was longer. A nested order shows the same effect at a bigger scale: 282 bytes down to 175 bytes, saving 107 bytes.

Strings, and the rupee sign

Spaces inside a quoted string are part of the value, so they are kept exactly: a note reading "keep these spaces" keeps its double and triple spaces while the file around it drops from 64 bytes to 55 bytes. Bytes are counted in UTF-8, not in characters, which matters for Indian text. The rupee sign costs 3 bytes, so the string "₹500" is 8 bytes in total: one byte for each quote, three for the rupee sign, and one each for the three digits. A small file holding an item, notebook, and a price, "₹500", is 45 bytes and minifies to 36 bytes, saving 9 bytes, or 20.0 percent. For plain English text the byte count and the character count are the same, but for a rupee sign they are not, and the tool counts bytes.

Copying the result

The output box holds the minified JSON on a single line, and the Copy minified JSON button copies it to your clipboard. Paste it where it needs to go: into a settings file, a code editor, a message, or a form field that only accepts one line. The result is ordinary JSON, so anything that could read your original can read the minified version too. Keep the pretty version for reading and the minified version for sending, and paste the minified version into a formatter later if you need to read it again.

The common mistake

People paste the minified result back into the tool and expect it to shrink again. It will not: a file that is already on one line has no line breaks or indenting left to remove, so the second pass saves 0 bytes. Take {"ok": true}, which is 12 bytes: it has one space, after the colon, and minifying it gives {"ok":true}, which is 11 bytes, saving exactly 1 byte. A file with no spaces at all saves 0 bytes, and that is the correct answer: the file was already as small as it can be.

Frequently asked questions

What is the method behind the JSON Minifier?

It parses the input into data with JSON.parse, then writes the data back with no spaces using JSON.stringify. Nothing inside a string value is changed.

Does indenting change how much minifying saves?

Yes. The same profile saves 17 bytes with two-space indenting, from 81 to 64 bytes, and 25 bytes with four-space indenting, from 89 to 64 bytes. The result is identical either way.

How many bytes is the rupee sign in JSON?

Three bytes in UTF-8. The string “₹500” is 8 bytes in total: one byte for each quote, three for the rupee sign, and one each for the three digits.

Why did 149.50 become 149.5 in my minified JSON?

The tool reads numbers as values, then writes them in their shortest form. 149.50 and 149.5 are the same number, and 597.00 becomes 597 for the same reason.

Why does minifying a second time save nothing?

Because the file is already on one line, with no line breaks or indenting left to remove. A fully minified file saves 0 bytes, which is the correct answer.

More guides on the JSON Minifier

Try it yourself

Try the JSON Minifier — free, in your browser.

Open the JSON Minifier