TL;DR / Summary: Minifying JSON before a deploy saves bandwidth and hides the one thing you need when a config breaks. Minify the artifact, keep the readable source, and always validate before and after.
What minifying actually does
It removes whitespace and line breaks between tokens. Nothing else changes: keys, values, ordering, and types all survive.
That makes it safe in principle and dangerous in practice, because the diff becomes unreadable. A review tool that shows one enormous line is a review tool that does not get used.
The right split is to minify the artifact and never the source of truth.
Validate before minifying
A minifier that accepts invalid JSON is worse than no minifier, because it produces a file that fails at runtime instead of at build time.
Run a strict parser first. Common failures include trailing commas, comments, and single quotes, none of which are legal JSON.
Checks worth automating
- Parse validity — strict JSON parser, no lenient mode
- Key duplication — most parsers silently keep the last value
- Encoding — UTF-8 without a byte order mark
- Number precision — large integers can lose digits in some tooling
Each check catches a class of bug that minification would otherwise conceal inside a long line.
Where minification belongs in the pipeline
Generate the readable file, commit it, then minify as part of the build. The artifact the server receives is small; the repository stays reviewable.
Name the outputs differently: config.json for the source and config.min.json for the artifact. Ambiguous names cause deployments of the wrong file.
Minify the thing you ship, not the thing you read.
If the platform only reads one filename, keep the readable version elsewhere and document the build step in the repository.
Configuration that must stay readable
Some configs are edited in place on a server during an incident. Minified JSON in that situation is actively harmful.
For those files, keep a readable copy on the host and minify only what is served over the network. A five-minute incident is not the time to reformat a file by hand.
Secrets and comments deserve the same treatment: comments are not valid JSON, so any documented config needs to live in a different format.
Diffing and reviewing
Review the readable source, not the artifact. If a reviewer sees a single line of ten thousand characters, the review is theatre.
For deployments, compare the parsed structures rather than the text. A semantic diff shows what changed; a textual diff on minified JSON shows nothing useful.
Log the hash of the artifact alongside the deploy. It confirms which file actually reached the server.
When not to minify
If the file is small and served from a local disk, minification saves nothing measurable and costs readability.
If it is served with compression, the transfer saving is much smaller than the raw size difference suggests. Measure before optimising.
If a human edits it regularly, leave it alone. The best config is the one that can be fixed at 2am.
For a quick check on size and structure, the developer tools collection includes JSON formatting and conversion utilities that run locally, which is faster than pasting sensitive config into a random website. Validate, minify the artifact, and keep the readable copy under version control.
Size, compression, and when the saving is real
Minification removes whitespace, which compresses extremely well anyway. If the file is served with gzip or brotli, the transfer saving is often a small fraction of the raw difference.
That does not make minification pointless. It makes it a minor optimisation, and it should be evaluated as one rather than as a major performance win.
The cases where it matters most are large configuration bundles, files parsed at startup by constrained runtimes, and anything delivered over a slow link without compression.
Measure the compressed size, not the pretty-printed size.
If the saving is under a few kilobytes, skip it and keep the file readable. The next person to debug a deploy will thank you.
Secrets do not belong in the artifact
A minified config still contains every value in plain text. Minification is not obfuscation and must never be treated as protection for keys or tokens.
Keep secrets in environment variables or a secret store, and reference them at runtime. A config file that ships with credentials is a leak waiting for a repository to become public.
Check the artifact before every deploy for key-like strings. A simple pattern match catches the mistakes that reviews miss when the diff is one enormous line.
Checking the artifact after download
Compare the hash of the file on the server with the hash of the artifact you built. A mismatch means a stale deploy or a cached upload.
Do this as part of the deploy, not as an afterthought. A hash check takes a second and catches the most common release error.
Deploy the file you verified, and verify the file you deployed.