DevFormatter

JSON Minifier

 

JSON Minifier

How the JSON Minifier works

Last updated: November 2026

JSON (JavaScript Object Notation) is a text-based data format widely used for API responses and configuration files. A JSON minifier removes all unnecessary whitespace — spaces, tabs, and newlines — to produce the most compact valid JSON string.

Paste formatted JSON into the left panel and click Minify (or just paste — it minifies automatically). The right panel shows the minified output and the status bar shows the size reduction percentage.

All processing runs entirely in your browser using JSON.stringify() with no indent argument — your data never leaves your machine.

JSON Minification Reference

Minification removes all whitespace outside of string values. The resulting JSON is functionally identical — it parses to the same data structure:

Before

{
  "name": "Alice",
  "roles": [
    "admin",
    "user"
  ]
}

After

{"name":"Alice","roles":["admin","user"]}
Format Indent Typical size
Formatted (2-space) 2 spaces baseline
Formatted (4-space) 4 spaces ~10% larger
Minified none 20–40% smaller

Tips & Tricks

Minify then compress for best results

Minification and gzip/brotli compression are complementary. Minifying first removes structural redundancy in the JSON (whitespace), while compression handles repetitive string patterns. A minified JSON file typically compresses better than a formatted one because gzip's sliding window covers more meaningful content instead of repetitive whitespace — the improvement is most significant for deeply-nested JSON.

JSON.stringify re-orders object keys in some engines

V8 (Node.js, Chrome) preserves insertion order for string keys but sorts integer-like keys to the front. If key order matters for downstream consumers, verify after minification. The spec does not guarantee any particular key order in JSON objects.

Whitespace inside string values is preserved

The minifier only removes whitespace outside of string values. A string value like "hello world" (with extra spaces) is preserved exactly — those spaces are part of the data, not formatting.

Minification validates your JSON automatically

Because minification requires parsing the JSON (JSON.parse), any syntax errors — trailing commas, unquoted keys, comments — will be caught and reported before minification even begins. Use this tool as a quick lint check.

Set Content-Type to application/json in production

When serving minified JSON from an API, always set Content-Type: application/json; charset=utf-8. This enables the browser to auto-decompress when combined with Content-Encoding: gzip and allows HTTP/2 header compression to work efficiently.

jq -c is the fastest CLI minifier

The jq -c . command reads JSON from stdin, validates it, and outputs compact JSON. It is faster than Python's json module for large files and handles streaming via --stream. Install via brew install jq or apt install jq.

Minify JSON Programmatically

Node.js

const minified = JSON.stringify(JSON.parse(rawJson));
// No indent argument → compact output
// Save to file:
const fs = require('fs');
const minified = JSON.stringify(JSON.parse(fs.readFileSync('data.json', 'utf8')));
fs.writeFileSync('data.min.json', minified);

Python

import json

# Minify from string
minified = json.dumps(json.loads(raw), separators=(',', ':'))

# Minify from file
with open('data.json') as f:
    data = json.load(f)
with open('data.min.json', 'w') as f:
    json.dump(data, f, separators=(',', ':'))

CLI (jq)

# jq with -c flag outputs compact (minified) JSON
jq -c . data.json > data.min.json

# Python one-liner
python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin), separators=(',',':')), end='')" < data.json > data.min.json

# Node.js one-liner
node -e "const fs=require('fs'); fs.writeFileSync('data.min.json', JSON.stringify(JSON.parse(fs.readFileSync('data.json','utf8'))))"

Frequently Asked Questions

What is a JSON minifier?
A JSON minifier removes all unnecessary whitespace — spaces, tabs, and newlines — from a JSON string to produce the most compact valid representation. It reduces file size without changing the data. The resulting JSON is functionally identical to the original but takes fewer bytes to store and transmit.
Why minify JSON?
Minified JSON reduces payload size for API responses and static assets, which speeds up network transfer and reduces bandwidth costs. A formatted JSON file can be 20–40% larger than its minified equivalent due to whitespace. To go the other direction, use the JSON Pretty Print tool.
Is my JSON data sent to a server?
No. All processing runs entirely in your browser using JavaScript. Your data never leaves your machine.
How do I minify JSON in Node.js?
Use JSON.stringify(data) with no third argument: const minified = JSON.stringify(JSON.parse(rawJson)). Without an indent argument, JSON.stringify produces compact output with no whitespace.
How do I minify JSON in Python?
Use json.dumps() with separators=(',', ':'): json.dumps(json.loads(raw), separators=(',', ':')). The separators argument removes spaces after commas and colons.
What is the difference between minify and compress?
Minifying removes whitespace from the JSON text itself, producing valid JSON. Compression (gzip, brotli, deflate) encodes the bytes at a binary level — this is done by web servers and CDNs automatically for HTTP responses. You can minify and then compress for maximum size reduction.
Does minifying JSON change the data?
No. Minifying only removes whitespace characters (spaces, tabs, newlines) that are not inside string values. All keys, values, and structure are preserved exactly. The minified JSON parses to an identical data structure.
How much smaller does JSON get after minification?
Typically 10–40% smaller, depending on how much indentation the original had. A file formatted with 4-space indentation will shrink more than one with 2-space indentation. The actual reduction depends on nesting depth and the ratio of string content to whitespace.
Can I minify JSON that contains comments?
No. Standard JSON does not allow comments — a JSON parser will reject any file containing // comment or /* comment */. If your file uses comments, it is JSONC (JSON with Comments), used by VS Code config files. Strip comments first with a tool like strip-json-comments (Node.js) before minifying.
What is the difference between minified JSON and binary formats like MessagePack?
Minified JSON is still plain text — readable, debuggable, and compatible with every JSON parser. Binary formats like MessagePack or CBOR encode the same data as compact binary bytes, often 20–50% smaller than minified JSON and faster to parse. The trade-off is that binary formats require a specific library on both sides and lose human readability.
How do I minify a JSON file on the command line?
With jq: jq -c . input.json > output.json. The -c flag means compact output. With Python: python3 -c "import json,sys; print(json.dumps(json.load(sys.stdin), separators=(',',':')))" < input.json. With Node.js: node -e "process.stdout.write(JSON.stringify(JSON.parse(require('fs').readFileSync('input.json','utf8'))))".
Should I minify JSON in development?
No. Keep JSON pretty-printed in development so it is readable in logs, debuggers, and version control diffs. Minify only for production API responses, bundled assets, or storage where every byte counts. Most web frameworks and CDNs handle response compression (gzip/brotli) automatically, which makes manual minification a secondary concern for HTTP payloads.

Related Tools

Other free developer tools available on DevFormatter.