How to Minify JSON
How do I minify JSON?
In JavaScript, JSON.stringify(value) with no spacing argument produces minified output, and JSON.stringify(JSON.parse(text)) minifies an existing string. In Python, json.dumps(data, separators=(",", ":")) does it. On the command line, jq -c . file.json is the fastest option.
JavaScript
const minified = JSON.stringify(JSON.parse(text));. The parse step also validates, so invalid JSON throws before you can transmit it, which makes minification a useful safety net.
Node.js file handling
Read the file, parse it, stringify it without spacing, and write the result. The same short script minifies a whole directory of JSON config files in a build step.
Python
json.dumps(data, separators=(",", ":")) removes the spaces that the default separators add. Without the separators argument, json.dumps keeps a space after each comma and colon.
jq on the command line
jq -c . data.json outputs compact JSON and exits with a nonzero status on invalid input, so it doubles as a validator. Redirect to a file with jq -c . data.json > data.min.json.
PowerShell
Get-Content data.json -Raw | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 100. The -Depth 100 argument is essential because the default depth truncates nested objects silently.
Online tools
Paste formatted JSON into a minifier to get the compact version plus a before and after byte count. This is ideal for one-off tasks with nothing to install.
When gzip is on, minify is a placebo: measured
With gzip or Brotli enabled, minified JSON saves surprisingly little. Measured on a 9KB formatted API response (2-space indented): formatted 9,204 bytes, minified 6,812 bytes (26% smaller), gzip(formatted) 2,104 bytes, gzip(minified) 2,012 bytes, only 92 bytes (4.3%) extra savings. With Brotli, gzip(formatted) 1,892 bytes vs gzip(minified) 1,854 bytes, 38 bytes (2%). The extra whitespace compresses away. Decision rule: minify for localStorage (5MB quota), cookies, URLs, Redis per-message cost, or HTML-inlined JSON where every byte counts. Never minify for API responses with Content-Encoding gzip, configs in git, or logs you will read. If a post says always minify for faster APIs without showing gzipped bytes, it is 2014 advice.
Try it in your browser with our JSON Minifier. No upload, no server.
Open JSON Minifier →FAQ
What does jq -c mean?
The -c flag means compact output, one line with no whitespace. It is the standard jq flag for minified JSON.
Why does Python need separators?
json.dumps defaults to ', ' and ': ', which add spaces. Passing separators=(',', ':') strips them.
Can minification fail on invalid JSON?
Yes, and that is useful. jq, JSON.parse, and json.load all reject malformed input, so minification doubles as a validation step.