{"id":113,"date":"2026-11-16T09:20:00","date_gmt":"2026-11-16T09:20:00","guid":{"rendered":"https:\/\/www.masters-tool.com\/blog\/?p=113"},"modified":"2026-11-11T03:39:06","modified_gmt":"2026-11-11T03:39:06","slug":"json-minify-before-config-deploy","status":"publish","type":"post","link":"https:\/\/www.masters-tool.com\/blog\/json-minify-before-config-deploy\/","title":{"rendered":"Minifying JSON Before a Config Deploy"},"content":{"rendered":"<p><strong>TL;DR \/ Summary:<\/strong> 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.<\/p>\n<h2>What minifying actually does<\/h2>\n<p>It removes whitespace and line breaks between tokens. Nothing else changes: keys, values, ordering, and types all survive.<\/p>\n<p>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.<\/p>\n<p>The right split is to minify the artifact and never the source of truth.<\/p>\n<h2>Validate before minifying<\/h2>\n<p>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.<\/p>\n<p>Run a strict parser first. Common failures include trailing commas, comments, and single quotes, none of which are legal JSON.<\/p>\n<h3>Checks worth automating<\/h3>\n<ul>\n<li><strong>Parse validity<\/strong> \u2014 strict JSON parser, no lenient mode<\/li>\n<li><strong>Key duplication<\/strong> \u2014 most parsers silently keep the last value<\/li>\n<li><strong>Encoding<\/strong> \u2014 UTF-8 without a byte order mark<\/li>\n<li><strong>Number precision<\/strong> \u2014 large integers can lose digits in some tooling<\/li>\n<\/ul>\n<p>Each check catches a class of bug that minification would otherwise conceal inside a long line.<\/p>\n<h2>Where minification belongs in the pipeline<\/h2>\n<p>Generate the readable file, commit it, then minify as part of the build. The artifact the server receives is small; the repository stays reviewable.<\/p>\n<p>Name the outputs differently: <code>config.json<\/code> for the source and <code>config.min.json<\/code> for the artifact. Ambiguous names cause deployments of the wrong file.<\/p>\n<blockquote><p>Minify the thing you ship, not the thing you read.<\/p><\/blockquote>\n<p>If the platform only reads one filename, keep the readable version elsewhere and document the build step in the repository.<\/p>\n<h2>Configuration that must stay readable<\/h2>\n<p>Some configs are edited in place on a server during an incident. Minified JSON in that situation is actively harmful.<\/p>\n<p>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.<\/p>\n<p>Secrets and comments deserve the same treatment: comments are not valid JSON, so any documented config needs to live in a different format.<\/p>\n<h2>Diffing and reviewing<\/h2>\n<p>Review the readable source, not the artifact. If a reviewer sees a single line of ten thousand characters, the review is theatre.<\/p>\n<p>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.<\/p>\n<p>Log the hash of the artifact alongside the deploy. It confirms which file actually reached the server.<\/p>\n<h2>When not to minify<\/h2>\n<p>If the file is small and served from a local disk, minification saves nothing measurable and costs readability.<\/p>\n<p>If it is served with compression, the transfer saving is much smaller than the raw size difference suggests. Measure before optimising.<\/p>\n<p>If a human edits it regularly, leave it alone. The best config is the one that can be fixed at 2am.<\/p>\n<p>For a quick check on size and structure, <a href=\"https:\/\/www.masters-tool.com\/\">the developer tools collection<\/a> 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.<\/p>\n<h2>Size, compression, and when the saving is real<\/h2>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<blockquote><p>Measure the compressed size, not the pretty-printed size.<\/p><\/blockquote>\n<p>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.<\/p>\n<h2>Secrets do not belong in the artifact<\/h2>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<h2>Checking the artifact after download<\/h2>\n<p>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.<\/p>\n<p>Do this as part of the deploy, not as an afterthought. A hash check takes a second and catches the most common release error.<\/p>\n<blockquote><p>Deploy the file you verified, and verify the file you deployed.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":40,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool-tutorials","entry","has-media"],"_links":{"self":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":1,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/posts\/113\/revisions\/114"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/media\/40"}],"wp:attachment":[{"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.masters-tool.com\/blog\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}