JSON Minifier

Remove all whitespace from JSON and see exactly how many bytes you saved. Runs locally in your browser.

0 characters
1

Overview

Pretty-printed JSON is for people. The indentation and line breaks that make a config readable are meaningless to a parser, and in a deeply nested document they can take up close to half the bytes. Minifying removes all of that whitespace and produces the smallest text that parses to exactly the same data.

Paste JSON and press Minify or Ctrl/⌘+Enter. The status bar shows the size before and after in UTF-8 bytes and the percentage saved. Use Beautify to expand it again. The input is parsed and re-serialized in your browser, so invalid JSON is reported rather than quietly passed through, and nothing is uploaded.

What minification removes, and why the data is unchanged

RFC 8259 defines four whitespace characters (space, tab, line feed and carriage return) that may appear before or after any of the six structural characters { } [ ] : ,. The specification calls this whitespace insignificant, and every conforming parser discards it. Removing all of it is therefore always safe.

Whitespace inside strings is data and is kept. In {"note": "two spaces\n"}, the double space and the escaped newline survive minification exactly. Only the space after the colon goes away.

Because this tool re-serializes the parsed value instead of deleting characters with a regular expression, some things are normalized along the way. None of these change the meaning for a JavaScript consumer, but you should know about them:

  • Number formatting is canonicalized: 1.0 becomes 1, 1e2 becomes 100.
  • Unnecessary escapes are written as plain characters: "é" becomes "é", which is one character but two UTF-8 bytes.
  • Integers above 253 lose precision, as they do in any JavaScript parser.
  • Integer-like keys move to the front: {"b":1,"2":0} becomes {"2":0,"b":1}. Duplicate keys collapse to the last value.

If a payload carries 64-bit IDs or high-precision decimals as bare numbers, minify it with jq -c (jq 1.7 or later) instead. It keeps number literals exactly as written.

A worked example

A single order record, indented with two spaces, is 286 bytes:

{
  "orders": [
    {
      "id": 1001,
      "status": "pending",
      "total": 49.99,
      "items": [
        {
          "sku": "A-100",
          "qty": 1
        }
      ],
      "customer": {
        "name": "Customer 0",
        "email": "user0@example.com"
      }
    }
  ]
}

Minified, it is 152 bytes, 47% smaller:

{"orders":[{"id":1001,"status":"pending","total":49.99,"items":[{"sku":"A-100","qty":1}],"customer":{"name":"Customer 0","email":"user0@example.com"}}]}

The ratio holds as the file grows. The same structure with 500 generated orders measured 134,301 bytes with two-space indentation, 108,799 bytes with tabs and 71,293 bytes minified. After gzip (default level) the difference shrinks sharply: 6,357 bytes for the indented version against 5,979 minified, about 6%. The exact numbers depend on your data, but the pattern is typical. Indentation is repetitive, and repetition is exactly what compression removes.

When minifying JSON matters

If your API already sends responses with gzip or Brotli, minifying them gives you only a small gain. It still saves CPU on both ends, since there is less text to compress and parse, but don't expect the raw 47%. Minification pays off more where nothing compresses the bytes:

  • Size-capped storage. Browser localStorage, cookies, message queues and key-value stores enforce limits on the raw size. Whitespace counts against them.
  • Environment variables and CLI arguments. A service-account key or a feature-flag config passed as an env var should be one line. Many .env loaders and CI secret stores handle multi-line values badly or not at all.
  • Log lines. JSON Lines needs each record on one line, so a pretty-printed object breaks every log shipper that splits on newlines.
  • Embedding in HTML. Inline data in <script type="application/json"> ships with the page. Minify it, and also replace < with < so a string containing </script> cannot end the tag early. Minification alone does not do that.
  • Embedding in another string. When the JSON becomes a string value inside other JSON, every newline and quote must be escaped. Minify first, then use the JSON escape tool.

Keep the formatted version in source control, where readable diffs matter, and minify at build or deploy time.

Minifying JSON in code

// JavaScript / Node.js
const compact = JSON.stringify(JSON.parse(text));

# Python: the default separators include spaces, so set them explicitly
json.dumps(data, separators=(",", ":"), ensure_ascii=False)

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

The Python call needs both arguments. Plain json.dumps(data) writes ", " and ": " between items, and its default ensure_ascii=True turns every non-ASCII character into a six-byte \uXXXX escape. In text with many accented or CJK characters that can make the "minified" output larger than the original. To check the input before you minify, or to read the result as a tree, use the JSON validator or the JSON viewer.

Frequently Asked Questions

Can minifying JSON break anything?

Not for a standard parser. The only removed characters are whitespace outside strings, which RFC 8259 defines as insignificant. Code that compares JSON text byte for byte, such as a signature over the raw body, will see a difference. Sign the exact bytes you send.

How do I un-minify JSON?

Click Beautify, which re-indents using the spacing selected in the toolbar. Formatting and minifying are lossless in both directions for the data itself.

Is minified JSON the same as compressed JSON?

No. Minified JSON is still plain text that any parser reads directly. Compression such as gzip produces binary data that must be decompressed first. The two stack, but most of the benefit of minifying disappears once the data is compressed.

Why is the byte count different from the character count?

The savings are measured in UTF-8 bytes, which is what goes over the network and into storage. Characters outside ASCII take two to four bytes each, so a document with emoji or non-Latin text has more bytes than characters.

Does the minifier upload my data?

No. Parsing and serialization run in your browser, with large inputs handled in a local Web Worker. The last input is saved in this browser's local storage until you clear it.