Minifying JSON is easy. Knowing whether it changes anything users can feel is the part worth thinking about.
JSON permits whitespace between tokens, so line breaks and indentation can be removed without changing the parsed values. The result is smaller and less readable, which makes it appropriate for transport but poor as a hand-edited source file.
Table of contents
- What minification changes
- Safe ways to minify JSON
- Minification versus compression
- Treat online tools with caution
- How this fits the rest of the stack
- FAQ
What minification changes
A minifier removes spaces, tabs, and newlines outside strings. It must preserve whitespace inside string values, number syntax, escape sequences, key order as written, and every value. Comments are not valid JSON, so tools that accept them may actually be processing JSON5 or another format.
{"name":"RunxBuild","active":true,"limits":[10,20]}
Safe ways to minify JSON
jq -c . input.json > output.json
python -m json.tool --compact input.json > output.json
Both commands parse before writing, which catches invalid input. In JavaScript, JSON.stringify(JSON.parse(text)) is appropriate for trusted-size data; handle parse errors and do not feed unbounded uploads into memory.
Minification versus compression
Minification reduces the original byte count, but gzip or Brotli usually removes repeated structure far more effectively. For an HTTP API, enabling transport compression and avoiding unnecessary fields often has a larger impact than removing every newline.
Measure the minified and compressed sizes together. A tiny configuration file may not justify a build step, while a large static dataset can benefit from both.
Treat online tools with caution
Do not paste API keys, customer records, tokens, or private configuration into an unknown JSON minifier. Use a local command or a tool your organisation has reviewed. Minification is a formatting operation, not anonymisation.
Keep the readable source under version control and generate the minified artifact during the build. That preserves useful diffs while delivering compact output.
How this fits the rest of the stack
Minify at the build boundary, compress in transit, and optimise the data model before chasing punctuation bytes. Test the impact, then model the deployment with the RunxBuild calculator and ship through the RunxBuild dashboard.
Useful related references:
- XML to JSON: The Conversions That Are Not Actually Lossless
- Unescape JSON: Why Your String Has Backslashes In It
- Should package-lock.json Be Committed?
- Services on RunxBuild
FAQ
Does minifying JSON change the data?
A correct minifier removes only insignificant whitespace, so parsing the result produces the same values.
Is minified JSON encrypted?
No. It remains plain text and should not be used to protect secrets.
Is JSON minification better than gzip?
They are complementary, but transport compression normally saves more. Measure both on representative payloads.
Can JSON contain comments?
Standard JSON cannot. If a file has comments, identify the actual format before processing it.