JSON minification removes all unnecessary whitespace — spaces, tabs, and newlines — to reduce file size. This is essential for production APIs and web applications where every byte counts.

Why minify JSON?

  • Faster API responses — less data to transmit over the network
  • Lower bandwidth costs — especially important at scale
  • Faster parsing — less characters to process

A typical formatted JSON response is 20–50% larger than its minified equivalent. With gzip compression on top, the savings are smaller but still meaningful.

Method 1: Online JSON minifier (instant)

Try it free — JSON Minifier

Paste your JSON and get the minified version instantly. Shows exact size savings.

Open tool →

Method 2: Minify in JavaScript

// Parse then stringify without space parameter
const minified = JSON.stringify(JSON.parse(formattedJSON));

// Or if you already have a JS object
const obj = { name: 'Alice', age: 28 };
const minified = JSON.stringify(obj);
// '{"name":"Alice","age":28}'

// Size comparison
const formatted = JSON.stringify(obj, null, 2);
console.log('Formatted:', formatted.length, 'bytes');
console.log('Minified:', minified.length, 'bytes');
console.log('Saved:', Math.round((1 - minified.length/formatted.length)*100) + '%');

Method 3: Minify in Python

import json

# From a string
formatted = '{ "name": "Alice", "age": 28 }'
minified = json.dumps(json.loads(formatted), separators=(',', ':'))
# '{"name":"Alice","age":28}'

# The key: separators=(',', ':') removes spaces after , and :
# Default separators are (', ', ': ') which add spaces

# From a file
with open('data.json') as f:
    data = json.load(f)

with open('data.min.json', 'w') as f:
    json.dump(data, f, separators=(',', ':'))

Method 4: Command line

# Using Python (no install needed)
python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin),separators=(',',':')))" < input.json > output.min.json

# Using jq
jq -c . input.json > output.min.json

# Using Node.js
node -e "process.stdout.write(JSON.stringify(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'))))" < input.json

Should I minify manually or let the server do it?

For APIs, let your web server handle it. Enable gzip/Brotli compression in Nginx or your CDN — this typically reduces JSON by 60–80%, far more than minification alone. Minification + compression = best results. Only manually minify if you're shipping static JSON files without a server.