Skip to content
HandyKit

JSON Minifier

Remove whitespace from JSON to make it as small as possible, and see how much you save before and after gzip compression.

Runs in your browser. Your input is never uploaded or stored.

What is JSON minification?

Minifying JSON removes the spaces, tabs and line breaks between values, so the same data takes up fewer bytes. Whitespace inside strings is kept, because it is part of the data.

Formatted JSON (98 bytes):

{
  "id": 42,
  "user": {
    "name": "Ada",
    "roles": [
      "admin",
      "dev"
    ]
  }
}

The same data minified (55 bytes), 44% smaller:

{"id":42,"user":{"name":"Ada","roles":["admin","dev"]}}

How to minify JSON

  1. Paste your JSON into the input, select Open file, or drop a file onto it.
  2. Select Minify, or press Ctrl + Enter (⌘ + Enter on Mac).
  3. If there is a syntax error, the message shows its line and column with a suggested fix.
  4. Select Copy or Download to use the result. The size table shows how much you saved.

How much does minifying save?

It depends on how the JSON was formatted. Deeply nested JSON indented with four spaces can shrink by half; JSON that is already compact barely changes.

Over the network the saving is usually much smaller, because servers compress JSON responses with gzip or Brotli, and compression is very good at squeezing repeated whitespace. That is why this tool shows two numbers: the raw saving and the saving after gzip. If the gzipped saving is a few percent, minifying a compressed API response won't make a noticeable difference.

When to minify JSON

Minify when bytes matter and compression is not available or the JSON is embedded somewhere:

  • Storing JSON in environment variables, database columns, cookies or local storage.
  • Embedding JSON in HTML, such as <script type="application/ld+json"> or data- attributes.
  • Putting JSON in a URL or a command-line argument, where line breaks cause trouble.
  • Writing test fixtures or log lines that should fit on one line.

Keep JSON formatted when people read or review it. Configuration files in a Git repository, for example, are easier to edit and produce cleaner diffs when they are indented.

Minifying JSON in code

Most languages can minify JSON in one line, but check how they treat numbers:

// JavaScript: re-serialises the data, which rounds integers above 2^53
JSON.stringify(JSON.parse(text));
# jq
jq -c . data.json
# Python: separators remove the spaces after commas and colons
json.dumps(json.loads(text), separators=(",", ":"))

The JavaScript approach goes through JSON.parse, so a large ID such as 12345678901234567890 comes out as 12345678901234567000. This minifier works on the text itself and keeps every number exactly as written.

Frequently asked questions

Does minifying change my data?

No. Only whitespace between values is removed. Strings, including any spaces inside them, numbers and key order stay exactly as written, and integers too large for JavaScript are not rounded.

Is minified JSON still valid JSON?

Yes. Whitespace between values has no meaning in JSON, so the minified text parses to exactly the same data as the original.

How do I turn minified JSON back into something readable?

Paste it into the JSON Formatter, which adds indentation and line breaks. Formatting and minifying are exact opposites, so you can go back and forth without losing anything.

Why sort keys when minifying?

Sorting gives the same output for the same data regardless of the original key order. That makes minified JSON easier to compare, hash or cache. Arrays keep their order, because order matters in arrays.

Is my JSON uploaded or saved anywhere?

No. Minifying runs in this browser tab, and opening a file reads it on your device. Nothing is sent to a server, logged, or kept in browser storage.

Guides

  • · 2 min read

    Minify JSON: What It Does and When to Use It

    What minifying JSON removes, what it never changes, when it is worth doing and when it is not, and why sorting keys gives stable output you can compare or hash.