JSON Minify

Minify JSON by removing every unneeded space and line break.

Local Your input is processed locally in your browser. Found a problem? Report an issue

What JSON Minify does

JSON Minify removes all whitespace that is not inside a string, producing the smallest equivalent JSON text. It also validates the input first, so you never minify a broken document by accident. For line-delimited JSON it minifies each record onto its own line.

Using JSON Minify

  • Minify gives compact output and Validate checks without rewriting.

JSON Minify examples

The built-in sample

Input

{
  "name": "Ada Lovelace",
  "active": true,
  "tags": ["math", "code"],
  "address": { "city": "London" }
}

Output

{"name":"Ada Lovelace","active":true,"tags":["math","code"],"address":{"city":"London"}}

This is the input that the Load sample button fills in.

Whitespace inside strings is data

Input

{
  "title": "  two  spaces  ",
  "tags": [ "a", "b" ],
  "ratio": 0.50
}

Output

{"title":"  two  spaces  ","tags":["a","b"],"ratio":0.5}

Only whitespace between tokens is removed. The spaces inside "title" are part of the value and stay. Because the text is re-written from the parsed data, 0.50 is also shortened to 0.5.

Each output was produced by running this tool on the input above it.

How it works

The text is parsed in a Web Worker and written out again with no whitespace between tokens. Invalid input is never minified; you get the line and column of the first error instead.

Details and limits

  • The output is the shortest standard encoding of the same data, so besides whitespace it also drops needless digits (1.50, 1e3) and turns \u00e9 into the character itself.
  • Line-delimited JSON stays line-delimited: each record is minified onto its own line.
  • Duplicate keys collapse to the last value, exactly as in the JSON Formatter.
  • Input that is not valid JSON stops the tool, and the status line shows where the problem is. The JSON Validator page lists the usual causes.

Worked example: Compressing a 312-byte indented config down to 168 bytes

Suppose you have a human-readable 14-line configuration payload (312 bytes) that you need to store inside a single-line .env variable or HTTP header:

{
  "service": "payment-worker",
  "retryPolicy": {
    "maxAttempts": 4,
    "backoffMs": [250, 1000, 4000],
    "retryableCodes": [429, 502, 503, 504]
  },
  "logMessage": "Retrying   after   timeout"
}

When you run JSON Minify, the parser removes every newline, indentation space, and space after : and , outside of string literals, while strictly preserving the multiple spaces inside "Retrying after timeout":

{"service":"payment-worker","retryPolicy":{"maxAttempts":4,"backoffMs":[250,1000,4000],"retryableCodes":[429,502,503,504]},"logMessage":"Retrying   after   timeout"}

The payload shrinks from 312 bytes to 166 bytes (a 46.8% reduction) and fits cleanly on a single line.

Limits and what this tool cannot do

  • Requires valid JSON input: Because minification parses the JSON token stream first (JSON.parse followed by JSON.stringify), any syntax error—such as a trailing comma, comment, or unescaped newline inside a string—must be fixed before the JSON can be minified.
  • Does not shorten key names or compress values: Minifying strips structural whitespace; it does not rename "retryableCodes" to "r" or apply binary Gzip/Brotli compression.
  • Numbers exceeding 53-bit IEEE 754 precision: Unquoted 64-bit integers above 9,007,199,254,740,991 lose last-digit precision when parsed as IEEE 754 floats; wrap 64-bit IDs in quotes.

Questions

How much smaller does minified JSON get?

By exactly the whitespace between tokens, so it depends on how the input was indented and how deeply it is nested. If the response is served with gzip or Brotli compression the saving is much smaller, because repeated whitespace compresses well.

Why shouldn't I just use Find & Replace to delete all spaces in a JSON file?

Deleting all spaces with regex or Find & Replace corrupts string values—turning "New York" into "NewYork". A true JSON minifier parses the syntax tree so whitespace inside quoted string values is never touched.

How do I put minified JSON inside a bash .env file or curl -d command?

Wrap the minified single-line JSON in single quotes (PAYLOAD='{"key":"value"}'), or use the JSON Escape tool if it needs to sit inside double quotes.

How do I un-minify a 1-line JSON file back into readable lines?

Open the JSON Formatter tool and paste the minified line to re-indent it with 2 or 4 spaces.