Minifying sounds destructive. The word suggests squeezing, and squeezing data sounds like a good way to break it. So before pasting a payload or a config file into a minifier, it is reasonable to ask the blunt question: what exactly comes out, and can any of it be something I needed?

The answer is narrower than most people expect, and that narrowness is the safety case. The JSON Minifier on Ovatly removes whitespace only. This guide walks through what that means character by character, what is preserved and why, and what happens when the input is not valid JSON at all.

Contents

  • Quick answer
  • The only thing removed: whitespace
  • Strings keep every character
  • What is preserved exactly
  • Worked example: 38 bytes to 29, character by character
  • Invalid input is reported, never half-minified
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

A JSON minifier removes whitespace only: indentation, line breaks and the spaces around separators. Those characters are formatting for humans and a parser ignores them, so removing them changes nothing about the data. Values, key order and key names are preserved exactly, spaces inside strings survive because they are data, and the output parses to exactly the same value as the input. Paste your JSON into the JSON Minifier and the report shows the saving: the entry example goes from 38 bytes to 29 bytes, a 23.7 percent saving. Invalid JSON is refused with its parse error, never half-minified.

The only thing removed: whitespace

JSON has two kinds of characters. Structural characters and data characters do the work: braces, brackets, quotes, colons, commas, and the letters and digits inside values. Whitespace does none of it. The spaces that indent a nested object, the line break after each key, the single space after a colon: a parser skips all of it. It exists so a human can see the shape of the data.

Minifying deletes exactly that second kind and nothing from the first. Indentation goes. Line breaks go. The spaces around separators go. What remains is the same structure and the same data, written as one continuous line. Because the removed characters carried no meaning, the minified text and the pretty text are interchangeable to any program that reads them.

This is also why the saving varies so much between files. The minifier can only return the bytes the formatting was using. A deeply indented file gives back a lot; a file an API already served in compact form gives back almost nothing, and the report will say 0 percent, which simply means there was no whitespace left to remove.

Strings keep every character

The one place whitespace does carry meaning is inside a string. The space in "name": "My API" is not formatting; it is part of the value, and removing it would change the data. So minifying draws the line exactly where the JSON grammar draws it: whitespace between tokens is removed, whitespace inside quotes is left alone.

The same care applies to everything else inside the values. Numbers stay as written, text stays spelled as written, and nothing is rounded, re-encoded or reworded. If a string contains an escaped character sequence, it comes through as the same sequence. The tool is not interpreting your data; it is republishing it without the padding around it.

What is preserved exactly

Three preservations are worth naming, because they are the ones people worry about. Key order is preserved: the keys come out in the order they went in, so a file whose readers care about ordering behaves identically. Key names are preserved: nothing is shortened to single letters or renamed for compactness, which is a different and much riskier kind of shrinking that this tool does not do. And values are preserved: the minified output parses to exactly the same value as the input, which is the test that matters. Any standard parser, given either version, builds the same object.

Size, by the way, is measured in UTF-8 bytes rather than characters, so text outside plain ASCII counts for more than one byte per character in the report. That affects the numbers, not the data: it is the honest way to count what will actually be stored or sent.

Worked example: 38 bytes to 29, character by character

Here is a small pretty-printed input, 38 bytes in total:

{
  "name": "Ovatly",
  "tools": 250
}

And here is the same data after minifying, at 29 bytes:

{"name":"Ovatly","tools":250}

Nine bytes came out, and every one of them can be accounted for. Three are line breaks: after the opening brace, after the first value and after the second. Four are indentation: the two spaces before "name" and the two before "tools". The last two are the spaces after the colons, one in each pair. Three plus four plus two is the whole 23.7 percent saving.

Notice what is still there. The space inside "Ovatly" was never a candidate, because there is none to remove, but if the value had been "My API" its internal space would have survived untouched. The keys are in the original order, the number is the same number, and a parser cannot tell which of the two texts it was given.

Invalid input is reported, never half-minified

Safety also means failing cleanly. If the input is not valid JSON, a trailing comma, a missing bracket, an unquoted key, the minifier reports the parse error and produces no partial output. There is no half-processed file that looks finished and fails later somewhere else.

That behaviour makes the tool a reasonable first check on any JSON you are about to hand to another system. A clean minify confirms the syntax parses; a refusal tells you there is a structural error and names it, while the file is still in front of you. Our workflow guide on minifying JSON for an API payload or config file builds that check into a shipping routine.

Limitations and honest tradeoffs

Whitespace is all that comes out, so minifying cannot rescue a bloated data design. Long descriptive key names repeated in every record, and long values, cost what they cost in both versions. If a payload is too big, the fix is in the data, not the formatting.

The output is also deliberately unfriendly to read. One line means no useful line numbers, painful diffs and hard visual scanning, which is why the pretty version should always be kept as the file you edit and review. And the measurement is in UTF-8 bytes: for text heavy in non-ASCII characters the byte saving will look different from a character count, because the two are counting different things.

Common mistakes

  • Expecting the minifier to shrink the data. It removes formatting, not content. Key names and values are preserved on purpose.
  • Worrying that spaces inside strings will vanish. They are data, and they survive. Only whitespace between tokens is removed.
  • Treating a 0 percent saving as a failure. It means the input was already compact. The report is a measurement, not a grade.
  • Editing the minified output. It parses to the same value, but it is the wrong file to maintain. Edit the pretty version and minify again.
  • Ignoring a refused paste. A parse error at minify time is the earliest warning you will get. Fix the source rather than working around the message.

FAQs

What exactly does a JSON minifier remove? Whitespace only: the indentation at the start of lines, the line breaks between items, and the spaces around separators such as colons and commas. That whitespace is formatting for human readers; a JSON parser ignores it.

Will minifying change my data? No. Values, key order and key names are preserved exactly, and the minified output parses to exactly the same value as the input. Even the spaces inside a string survive, because they are part of the value.

How much space does minifying save? Only the whitespace comes out, so the saving matches the formatting the input carried. The entry example goes from 38 bytes to 29 bytes, a 23.7 percent saving. A report of 0 percent means the input was already compact.

What happens if my JSON has an error in it? The minifier reports the parse error and produces no partial output. Nothing is half-minified, so a broken file cannot slip through looking processed.

Is it safe to paste sensitive JSON into the minifier? The Ovatly JSON Minifier runs fully locally in your browser and nothing is uploaded. The check is worth making with any online tool, but here the processing never leaves your device.

Conclusion

A JSON minifier is safe precisely because its job is so limited: whitespace out, everything else preserved exactly. Strings keep their characters, keys keep their order and names, the output parses to the same value, and invalid input is refused instead of half-processed. Try it with the JSON Minifier and read the byte report on your own file. For more guides in this series, see our Data and JSON Tools guides.

References