← All blog posts

Common mistakes people make with the JSON Minifier

WhiteUI · A plain-English guide to the JSON Minifier

Most poor results from the JSON Minifier are not faults in the tool. They are small slips: a comma where JSON does not allow one, a quote mark of the wrong kind, or an expectation the tool was never meant to meet. The tool itself uses exact arithmetic, so when a result looks wrong, the input or the way the result is used is usually the cause, and each of the five mistakes below has a quick fix.

At a glance

Already-minified input: 1 of 12 bytes savedSaved 1 byteKept 11 bytes12 → 11 bytes · 8.3% smaller
Minifying an almost-minified input saves only 1 of 12 bytes: the result is 11 bytes, which is 8.3 percent smaller.

Mistake 1: a comma after the last item

JSON does not allow a comma after the last item in an object or a list, but many other formats do, so people add one out of habit. A file written as a on one line, b on the next, and then a comma before the closing brace, is 23 bytes and invalid: the tool reports an error at position 22, which is where the closing brace sits after the stray comma. Remove that one comma and the file minifies at once, from 22 bytes to 13 bytes, saving 9 bytes. When the tool reports an error, check the last item in each list first.

Mistake 2: single quotes instead of double quotes

JSON only accepts double quotes around labels and words. Single quotes work in JavaScript and Python, so people paste in a file written with them, such as {'name': 'Priya'}, and the tool says it is invalid. The fix is to use double quotes throughout, as in {"name": "Priya"}. If your file comes from another program, check its export settings: some programs write single quotes by default, and the file needs converting before any JSON tool can read it.

Mistake 3: expecting the words inside strings to shrink

People paste in a file, see a small saving, and assume the tool missed something, because the words inside the strings are still long. The tool did not miss them: it is not allowed to touch them. A file with a message, "hello world", and a note, "keep these spaces", goes from 64 bytes to 55 bytes, saving 9 bytes, or 14.1 percent, and the double and triple spaces inside the note are still there in the result. The saving comes only from the spacing between pieces of data, so a file full of long strings saves a smaller share than a file full of structure.

Mistake 4: minifying a file that is already minified

Minifying twice does not save twice. A file that is already on one line has no line breaks or indenting left to remove, so the second pass saves nothing, or almost nothing. Take {"ok": true}, which is 12 bytes: it has one space, after the colon, and minifying it gives {"ok":true}, which is 11 bytes, so exactly 1 byte is saved, or 8.3 percent. A file that is already fully minified saves 0 bytes. If the tool reports 0 bytes saved, your file was already minified, and that is a good result, not a failure.

Mistake 5: copying the input instead of the output

The input box and the output box sit side by side and look alike, so people copy the text from the input box and paste the pretty version where the minified version was meant to go. The output box holds one long line with no line breaks; the input box holds the spaced-out version you pasted in. If what you pasted has line breaks in it, you copied the wrong box. Use the Copy minified JSON button instead of selecting the text by hand, and the right box is copied every time.

Worked check

Check any answer against the anchor: the default example is 22 bytes, and the minified result is 13 bytes, saving 9 bytes. Paste the default example in, and if the big line does not read 9 bytes, something was added or removed on the way in. One check, five seconds, and you know whether the file on screen is the one you meant to minify.

Frequently asked questions

What is the most common JSON Minifier mistake?

A comma after the last item in an object or a list. JSON does not allow it, and the tool reports an error instead of a result until the comma is removed.

Why does my JSON say invalid when it looks fine?

The usual causes are a trailing comma, single quotes instead of double quotes, or a missing quote. The tool shows the error message and leaves your input in place so you can fix it.

Why did minifying save only 1 byte?

Because the file was already almost minified. {"ok": true} is 12 bytes and minifies to 11 bytes, saving exactly 1 byte, and a fully minified file saves 0 bytes.

Are spaces inside strings removed by minifying?

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

Try it yourself

Try the JSON Minifier — free, in your browser.

Open the JSON Minifier