Input
1
Minified
Minified JSON will appear here...

What is JSON Minification?

JSON minification (also called JSON compression or JSON uglification) removes all whitespace characters — spaces, tabs, and newlines — that are not part of string values. The result is the smallest valid JSON string that a parser can read. The data is 100% identical to the original; only the formatting is removed. Everything runs in your browser with no data sent to any server.

Why Minify JSON?

Minifying JSON reduces bandwidth and improves API response times. A formatted JSON file with 4-space indentation can be 30–50% larger than its minified equivalent. For high-traffic APIs, mobile apps, or embedded systems with limited bandwidth, minification is a simple, zero-risk optimisation — no logic changes, no data loss.

How to Minify JSON in Python

Use json.dumps() with separators=(',', ':') to remove all whitespace:

import json
data = {"name": "example", "values": [1, 2, 3]}
minified = json.dumps(data, separators=(',', ':'))
# Result: {"name":"example","values":[1,2,3]}

How to Minify JSON in JavaScript

JSON.stringify() produces minified output by default (no third argument):

const data = { name: "example", values: [1, 2, 3] };
const minified = JSON.stringify(data);
// Result: {"name":"example","values":[1,2,3]}

Need to format it back? Use the JSON Formatter. Need to check if it's valid first? Use the JSON Validator. For a deeper look at when minification pays off and the pitfalls to avoid, read the full guide: How to minify JSON.

Before and after: what you actually save

The savings depend almost entirely on two things: how deeply nested your data is, and how wide the indentation was to begin with. Whitespace scales with nesting depth, so a deeply nested config file loses far more to minification than a flat array of records. The tool above shows the exact before and after byte count for your own input — but here is the rough shape of it for a typical API response:

Input format Size Saving vs. formatted
4-space indented 100 KB
2-space indented ~82 KB ~18%
Minified ~62 KB ~38%
Minified + gzip ~8 KB ~92%

Two things are worth noticing. First, minification alone is a solid but modest win — usually 20–50%. Second, the last row is doing most of the work, which brings us to the point most minifier pages skip.

Minification vs gzip and Brotli

If your goal is a smaller payload over the network, gzip or Brotli will almost always save you more than minification will — and if your server or CDN already has compression enabled, you are getting that saving whether you minify or not. Compression algorithms are extremely good at repeated byte sequences, and indentation is about as repetitive as data gets, so most of the whitespace you would strip by hand compresses down to almost nothing on the wire anyway.

That does not make minification pointless — the two compose. Minified-then-gzipped output is still smaller than formatted-then-gzipped output, just by a much narrower margin than the raw byte counts suggest. Minification also helps in the places compression does not reach: data stored at rest in a database column, a payload embedded in an HTML attribute or a JS bundle, a message going over a queue that does not compress, or a mobile client metered on stored bytes rather than transferred ones. The honest rule is: enable gzip/Brotli first, because that is the big win; minify second, where the bytes are stored rather than sent.

When to minify — and when not to

Minify when:

  • The JSON is an API response or request body that no human will read directly.
  • You are embedding JSON inside HTML, a JS bundle, or a data attribute.
  • You are storing many rows of JSON in a database and the storage cost is real.
  • You are pushing config or payloads to bandwidth-constrained or embedded devices.

Do not minify when:

  • The file is checked into git. Minifying destroys line-level diffs — one changed value shows up as the entire file changing, which makes code review and git blame useless.
  • A human edits it by hand — package.json, tsconfig.json, CI config, fixtures.
  • It is a log line or debugging artefact someone will need to read under pressure.
  • The saving is theoretical. If the file is 3 KB and served over a compressed connection, you are trading readability for nothing measurable.

Minification is a build-and-transport step, not a storage format for source files. If you have minified something you now need to read, paste it into the JSON Formatter — the round trip is lossless in both directions.

Minify JSON in code

The Python and JavaScript one-liners are above. For the command line and Go:

Command line (jq). The -c flag emits compact output, which makes this the quickest way to minify a file in place or as part of a pipeline:

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

# minify every JSON file in a directory
for f in *.json; do jq -c . "$f" > "min/$f"; done

Go. json.Marshal is already compact. To minify existing JSON bytes without unmarshalling into a struct, use json.Compact:

import (
    "bytes"
    "encoding/json"
)

var out bytes.Buffer
err := json.Compact(&out, formatted)   // formatted is []byte
// out.Bytes() is now minified

Common mistakes when minifying JSON

Stripping whitespace with a regex. The single most common bug. A naive replace(/\s+/g, '') also eats the spaces inside your string values, silently corrupting the data. Whitespace is only insignificant between tokens. Always minify by parsing and re-serialising — which is exactly what the tool above does.

Assuming minified means obfuscated. Minification is not a security measure. Every key and value is still there in plain text, one format away from being perfectly readable. Never treat it as a way to hide anything.

Minifying JSON Lines or NDJSON as one document. Those formats are one JSON value per line, where the newlines are structural. Minify each line separately, never the file as a whole.

Minifying broken JSON. A minifier has to parse before it can re-serialise, so invalid input fails rather than producing a smaller file. Check it with the JSON Validator first, or fix it with JSON Repair, then minify.

Frequently Asked Questions

What does minifying JSON do?

Minifying removes all whitespace (spaces, tabs, newlines) from JSON, producing the smallest valid string. The data is identical — only formatting is removed.

Why minify JSON?

Smaller JSON means faster API responses, lower bandwidth costs, and reduced payload size for mobile apps. A 10KB formatted file can often be reduced to 6–7KB.

Is minified JSON still valid?

Yes. Whitespace is not significant in JSON. Minified JSON is 100% valid and parseable by any JSON parser.

How much does JSON minification reduce file size?

Typically 20–50%, depending on how heavily the original was indented. A file using 4-space indentation with deep nesting will see larger gains than a shallowly-nested file with 2-space indentation.

How do I minify JSON in Python?

Use json.dumps(data, separators=(',', ':')). The separators argument removes the default spaces after commas and colons.

What is the difference between JSON minify and JSON compress?

In practice, the terms are used interchangeably. Technically, "minify" means removing whitespace, while "compress" could also refer to gzip/Brotli encoding for transfer. This tool does whitespace removal (minification). HTTP-level compression is handled separately by your server or CDN.

Should I minify JSON if my server already uses gzip?

For network transfer, gzip or Brotli saves far more than minification does, and indentation compresses extremely well — so the extra gain is small. Minification still helps where compression does not apply: JSON stored in a database, embedded in HTML or a JS bundle, or sent over an uncompressed queue. Enable compression first, then minify where bytes are stored rather than sent.

When should I not minify JSON?

Do not minify files that are checked into git (it destroys line-level diffs and makes code review painful), files a human edits by hand such as package.json or tsconfig.json, or logs someone may need to read while debugging. Minification is a build and transport step, not a source format.

Can I minify JSON with a regex?

No — this is the most common way to corrupt data. A pattern like replace(/\s+/g, '') also strips the spaces inside string values. Whitespace is only insignificant between tokens, so a safe minifier must parse the JSON and re-serialise it.

How do I minify JSON from the command line?

Use jq with the compact flag: jq -c . input.json > output.min.json. It parses and re-serialises, so it is safe on any valid JSON and works inside pipelines.