JSON Minifier (Compress JSON)

Output
Indent:
Examples:

Last updated: 2026-09-17

Paste formatted JSON to minify it and see the exact byte savings. The tool also estimates the gzip-compressed size so you know the real transfer cost. Everything runs locally in your browser.

What this tool does

Takes formatted JSON and removes all unnecessary whitespace, producing the smallest valid JSON representation. The tool shows the original byte count, the minified byte count, the percentage saved, and an actual gzip-compressed size estimate using the browser’s CompressionStream API.

The pipeline is straightforward: the input string is parsed with JSON.parse, then re-serialized with JSON.stringify and no spacing argument, which emits tokens with no whitespace between them. Byte counts are measured by wrapping the strings in a Blob and reading its size property. The gzip figure comes from piping the minified output through a CompressionStream('gzip') stream and summing the resulting chunks.

Example

Input (formatted, 98 bytes):

{
  "name": "myapp",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.18.0"
  }
}

Output (minified, 64 bytes):

{"name":"myapp","version":"1.0.0","dependencies":{"express":"^4.18.0"}}

The tool reports: raw 98 bytes, minified 64 bytes, saved 34.7%, gzip ~71 bytes.

When minification matters

Minification matters most for large JSON payloads delivered over a network. A 1MB API response with generous formatting may shrink to 600KB after minification and to 80KB after gzip. For small JSON files (under 10KB), the savings are negligible and readability is more important. The crossover point depends on the transport: on a gigabit LAN the transfer cost of extra whitespace is trivial, while on a satellite uplink or a dial-up fallback the same bytes add noticeable latency. Cache and CDN storage also factor in, because many edge nodes bill by stored bytes, so shrinking a frequently cached response lowers both egress and retention costs over time.

Minifying API responses

API responses are the most common reason to minify JSON. A single endpoint that returns a list of records can easily reach hundreds of kilobytes when pretty-printed, and that overhead is paid on every request.

Consider an endpoint returning 1,000 product records. Pretty-printed with 2-space indentation, the response body is around 480 KB. After minification it drops to roughly 310 KB, and with gzip applied to the minified body it compresses further to about 42 KB. On a mobile connection averaging 400 KB/s, the formatted version takes 1.2 seconds to transfer, the minified version takes 0.78 seconds, and the gzipped minified version takes 0.11 seconds. The wire time difference between formatted-plus-gzip and minified-plus-gzip is smaller but still measurable, because gzip has less redundant whitespace to exploit once minification has already collapsed it.

For paginated endpoints, the savings compound. If a client fetches 50 pages of 20 records each, shaving 170 KB off every response removes 8.5 MB of transfer across the full traversal. That matters on metered connections and on server egress budgets.

Minifying vs gzip

Minification and gzip solve overlapping but distinct problems, and they work at different layers.

Minification is a structural transformation applied to the text itself. It removes characters that carry no semantic meaning — spaces, tabs, newlines, and indentation — so the resulting string is a smaller but equivalent JSON document. The output is still JSON text; a parser reading it produces the same data structure. The reduction is bounded by how much whitespace the original contained, typically 15% to 40% for human-formatted input.

Gzip is a compression algorithm applied to the bytes on the wire. It finds repeated byte sequences and replaces them with short references, so a document with many repeated keys like "id", "name", and "created_at" compresses well regardless of whether it was minified first. Gzip operates transparently at the HTTP transport layer when the server sets Content-Encoding: gzip and the client sends Accept-Encoding: gzip.

The two techniques interact. Gzip already encodes repetition very efficiently, so minifying before gzip yields a smaller compressed result than gzipping the formatted version, but the extra gain is usually modest — often 5% to 10% on top of the gzip savings alone. The cases where minification matters most even with gzip enabled are small responses where the gzip header overhead is significant relative to the payload, and embedded or constrained clients that decompress but cache poorly.

Rule of thumb: enable gzip on your server first, because it gives the largest single win. Add minification when you control the producer and want to reduce both raw storage size and the gzipped transfer size, or when the consumer cannot use gzip.

When minification hurts

Minification is not always the right choice. There are concrete cases where it makes things worse or provides no benefit.

Human-readable files under active editing. Configuration files, test fixtures, and hand-written schemas are read and modified by people. Minifying them destroys diffs: a one-field change shows up as a change to the entire single-line document in version control. Keep these formatted and rely on gzip for transfer.

Already-minified input. Running the tool on JSON that has no whitespace produces zero savings and just rewrites the bytes. The tool detects this and reports 0%, but there is no reason to add the step to a pipeline.

Tiny payloads where gzip is enabled. Below roughly 1 KB, gzip overhead can exceed the whitespace savings, and the difference between formatted and minified is a few dozen bytes. The optimization is not worth the loss of debuggability.

Logs and audit trails that humans scan. When operators read JSON logs in a terminal or text viewer, minified single-line output is hard to scan. Many log viewers re-format on display, but if yours does not, minification slows incident response.

When the consumer re-serializes immediately. If the client parses the JSON and writes it back out with its own formatting, the minified form never reaches an end user. The only benefit is a small transfer-time reduction, which may be irrelevant on a fast internal network.

Common mistakes when minifying

Understanding the byte savings report

The report has four numbers, each measuring something different.

Raw bytes. The size of the original input string encoded as UTF-8, measured by constructing a Blob from the string and reading its size property. This is the exact number of bytes the formatted document occupies on disk or in memory before any processing.

Minified bytes. The size of the output after JSON.parse and JSON.stringify with no spacing argument. Same measurement method: Blob size in UTF-8 bytes. The difference between raw and minified is pure whitespace removal.

Saved percentage. Computed as (raw - minified) / raw * 100, rounded to one decimal place. A file with no whitespace reports 0.0%. Because the formula divides by the raw size, a small file with a lot of indentation can show a high percentage while saving only a few bytes, so read the percentage alongside the absolute byte counts.

Gzip estimate. The size of the minified output after being passed through CompressionStream('gzip'). This is a real gzip of the minified bytes, not a formula. It tells you what the transfer size would be if the server applied gzip to the already-minified document. Compare it against gzipping the raw input to decide whether minification adds value on top of compression for your specific payload.

The percentage reflects only whitespace savings, not compression. A document that minifies by 35% and then gzips by another 70% does not save 105%; the two reductions apply sequentially, so the final size is roughly 0.65 times 0.30, or about 19.5% of the original.

Minifying for embedded systems

Embedded devices, microcontrollers, and IoT gateways often fetch configuration or telemetry schemas over constrained links — cellular, LoRaWAN, or low-power Wi-Fi with tight duty cycles. On these links every byte costs airtime and battery, and many clients lack a gzip decompressor entirely because the decompression code would not fit in flash alongside the application.

In that environment, minified JSON is not a nicety but a practical wire format. A weather station posting a 220-byte formatted reading over LoRaWAN may be over the 51-byte payload limit for its data rate; minified, the same reading is around 140 bytes, and with shorter keys it can fit. The tool’s gzip estimate tells you when compression would help, and the raw minified size tells you what you actually send when the client cannot decompress.

Constrained devices also benefit from predictable parsing. Minified JSON from JSON.stringify has a stable shape: no optional whitespace, no trailing commas, consistent quoting. Embedded JSON parsers, which are often handwritten and brittle, handle the predictable form better than arbitrarily formatted input.

For devices that do support gzip, the report’s gzip estimate lets you budget the decompression RAM. A minified body of 40 KB that gzips to 9 KB tells you the device needs buffers for both the 9 KB compressed stream and the 40 KB inflated result, which matters on parts with 64 KB of RAM.

Do it in code

JavaScript:

const minified = JSON.stringify(JSON.parse(input));
// No second/third argument = no whitespace

Python:

import json
minified = json.dumps(json.loads(input), separators=(',', ':'))
# The separators argument removes spaces after , and :

CLI:

# jq (compact mode)
echo '{"a": 1, "b": 2}' | jq -c '.'

# Python one-liner
echo '{"a": 1, "b": 2}' | python -c 'import json,sys; print(json.dumps(json.load(sys.stdin)))'

Edge cases handled

Frequently asked questions

What does JSON minification do?
Minification removes all whitespace, line breaks, and indentation from JSON. The data is semantically identical — only the byte count is reduced. This is useful for API responses and file delivery where every byte counts.
How is the gzip size estimated?
The tool uses the browser's built-in CompressionStream API to actually gzip the minified output and report the real compressed size. This gives you an accurate picture of transfer size over HTTP with gzip enabled, not a rough estimate.
How much size does minification save?
It depends on how much whitespace the original has. A pretty-printed file with 2-space indentation typically shrinks by 20-40%. The tool shows exact before and after byte counts and percentages so you can see the actual savings.
Is minified JSON still valid?
Yes. Minified JSON is valid JSON — whitespace between tokens is optional per the JSON specification (RFC 8259). Any JSON parser can read minified output. The only difference is readability.
Should I minify JSON for production?
Minifying API responses reduces bandwidth and improves load times. However, for local development and debugging, formatted JSON is easier to read. Use minification for production delivery and keep formatted versions for development.
How do I minify JSON in the command line?
Use jq with the compact flag, passing -c to it. Pipe your JSON in and it prints a single-line minified version. For the same effect without jq, pipe the input through a Python one-liner that calls json.loads on stdin and json.dumps with compact separators on the result.
Does minification change the data or just the formatting?
Only the formatting. Keys, values, strings, numbers, booleans, and null are all preserved exactly. The tool parses the input with JSON.parse and re-emits it with JSON.stringify using no whitespace argument, so the output round-trips to the same data structure.
What happens to duplicate keys or non-standard JSON?
Because the input is parsed with JSON.parse first, duplicate keys collapse to the last value and trailing commas will cause a parse error. The tool reports invalid input instead of producing broken output, so you find formatting problems before shipping.
Is the gzip estimate the exact size my server will send?
Not exactly. The tool gzips the minified bytes using the browser CompressionStream API, which uses the same deflate algorithm as most servers. Real transfer size can differ slightly due to gzip header fields, compression level settings, and whether the server applies gzip before or after other transformations.

Related tools