Minified Output
Minifying the input above removes all whitespace between tokens:
{"name":"DevBento","version":"1.0.0","description":"Developer tools suite","features":["JSON Formatter","Base64 Encoder","UUID Generator","Regex Tester"],"config":{"theme":"dark","indent":2,"autoSave":true}}
The pretty-printed version is 233 bytes. The minified version is 189 bytes. That is a 19% reduction just from removing whitespace.
What Minification Removes
A JSON minifier removes exactly two categories of whitespace:
- Spaces, tabs, and newlines between tokens (between keys, colons, commas, brackets, and braces)
- Nothing inside quoted string values
This means {"message": "hello world"} minifies to {"message":"hello world"}. The spaces inside the string are data and are preserved. The space before the colon is syntactic and is removed.
Minification never changes key names, string values, numbers, or the structure of the document. If you minify a document and then pretty-print it, you get back the same data with fresh indentation.
Real Size Reduction Numbers
| Original size | Pretty-printed | Minified | Minified + gzip |
|---|---|---|---|
| Small config (1 KB) | 1,024 B | ~820 B | ~380 B |
| Medium API response (50 KB) | 51,200 B | ~41,000 B | ~8,500 B |
| Large dataset (1 MB) | 1,048,576 B | ~840,000 B | ~95,000 B |
Gzip dominates. Minification before gzip saves only a few percent on top of what compression already achieves. But on uncompressed static assets, every byte matters.
When Minification Matters
Minification produces meaningful savings in a specific set of situations:
Static JSON assets without consistent compression
Translation files, GeoJSON, embedded configuration, and bundled data files are often served from CDNs or embedded directly in build output. Compression is not always applied or may be inconsistent. Minifying these before deployment reduces the bytes your users download.
Logging and telemetry payloads
Log entries and telemetry events often get written to disk or sent over the wire millions of times per day. Minified JSON entries reduce storage costs and network overhead at that scale. A single log entry might shrink by 100 bytes. Across 100 million entries per day, that is 10 GB per day.
Embedded JSON in HTML
If you are embedding JSON in a <script> tag as initial page state (a common pattern for server-rendered React apps), the JSON is part of the HTML payload. Minifying it reduces the initial page size before the browser parses anything.
When Minification Does Not Matter
If your API server already sends Content-Encoding: gzip or Content-Encoding: br, minification adds negligible value. Verify this in your response headers:
curl -sI -H "Accept-Encoding: gzip" https://api.example.com/data | grep -i content-encoding
If you see content-encoding: gzip, your API is already compressing. Minification on top of that is not worth the readability cost during development.
Minifying JSON on the Command Line
jq with the -c (compact) flag outputs minified JSON:
jq -c . file.json
Minify a string inline:
echo '{"name": "Alice", "age": 30}' | jq -c .
# {"name":"Alice","age":30}
Python’s json module:
python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin), separators=(',', ':')))" < file.json
The separators=(',', ':') argument removes the default spaces after commas and colons. Without it, Python’s output includes spaces after each delimiter.
Node.js:
node -e "const fs=require('fs'); console.log(JSON.stringify(JSON.parse(fs.readFileSync('/dev/stdin','utf8'))))" < file.json
For scripts that need to minify many files, jq -c . is the fastest and most readable option.