Skip to content
AgileLogics

JSON Minifier

Strips all unnecessary whitespace from a JSON document, reducing its size for transfer or storage. The document must be valid JSON — invalid input is flagged with a parse error, never silently truncated.

How it works

Paste your JSON into the input panel and click Minify.

What does a JSON minifier do?

A JSON minifier removes every space, tab and line break that JSON allows between tokens, producing the same data on a single line in as few bytes as possible. It's used for payloads sent over the network, values stored in databases or environment variables, and JSON embedded in other files where size or a single line matters.

RFC 8259 calls that formatting "insignificant whitespace": parsers ignore it, so dropping it doesn't change what a program reads. Whitespace inside string values is part of the data and is always kept.

How to minify JSON

  1. Paste formatted or partly formatted JSON into the input box.
  2. Click Minify.
  3. Copy the single-line result from the output panel.

The input has to be valid JSON first. If it isn't, you'll see the parser's error message (with a line and column in Chrome and Edge) and no output. Use the JSON validator if you only want the yes/no check.

Worked example

This 331-byte order record, indented with two spaces:

{
  "order": {
    "id": 1042,
    "status": "shipped",
    "items": [
      {
        "sku": "A-100",
        "qty": 2,
        "price": 9.99
      },
      {
        "sku": "B-205",
        "qty": 1,
        "price": 24.5
      }
    ],
    "customer": {
      "name": "Ada Lovelace",
      "email": "ada@example.com"
    }
  }
}

minifies to 185 bytes, about 44% smaller:

{"order":{"id":1042,"status":"shipped","items":[{"sku":"A-100","qty":2,"price":9.99},{"sku":"B-205","qty":1,"price":24.5}],"customer":{"name":"Ada Lovelace","email":"ada@example.com"}}}

The saving depends on how deeply nested the data is and how it was indented. The same object with 4-space indentation is 443 bytes, so minifying it saves even more.

Minifying and gzip

Most web servers compress responses with gzip or Brotli, which already squeezes out repetitive whitespace. For the example above, gzip shrinks the indented version to 194 bytes and the minified one to 158. Minifying still helps, but by far less than the uncompressed numbers suggest. It matters more where nothing compresses the data: JSON stored in a database column, in local storage, in a URL, or inside an HTML page.

Side effects of re-serializing

The tool works by parsing your JSON and writing it back out with JSON.stringify. That's reliable, but it means the output is a fresh serialization, not your text with spaces deleted:

Input Minified output Why
{"id":1,"id":2} {"id":2} Duplicate keys keep the last value
{"a":"x","2":"y"} {"2":"y","a":"x"} Integer-like keys are ordered first
{"p":1.50,"q":1e3} {"p":1.5,"q":1000} Numbers are normalized
{"n":12345678901234567890} {"n":12345678901234567000} Above 2^53 - 1, integers lose precision
{"c":"é"} {"c":"é"} Unicode escapes are decoded

If your data contains IDs longer than 15 or 16 digits, store them as strings, or the minified file will hold different numbers than the original.

Minifying is also one-way in practice: the original indentation and key order can't be recovered. Keep the readable version in source control, and use the JSON formatter when you need to read a minified file again.

Other minifiers

Last updated

Frequently asked questions

Does minifying JSON change my data?
The values stay the same, but because the JSON is parsed and re-serialized a few things can change in the text. Duplicate keys collapse to the last one, integer-like keys such as "2" move to the front of their object, numbers are normalized (1.50 becomes 1.5), and integers above 2^53 - 1 lose precision.
Are spaces inside strings removed?
No. Only whitespace between tokens is removed. A value like "Ada Lovelace" with two spaces keeps both, because that whitespace is part of the data.
What happens if my JSON is invalid?
You get the parser's error message, such as "Expected double-quoted property name in JSON at position 7", and no output. The minifier never returns a partial or truncated result.
Is my JSON uploaded anywhere?
No. Minification uses your browser's JSON.parse and JSON.stringify, so the data stays on your device.
Should I minify JSON if my server already uses gzip?
It still helps, but much less than the raw size difference suggests. In the example on this page, minifying cuts the file from 331 to 185 bytes, while the gzipped sizes only drop from 194 to 158 bytes. Minifying matters most for JSON that isn't compressed in transit, such as values stored in a database or embedded in a page.