JSON Minifier

Remove all unnecessary whitespace from JSON and measure the saving.

Input
JSON input
Output
Result

About this tool


Minifying JSON parses the input and serialises it without indentation, newlines or spaces between tokens. It produces a compact representation of the parsed value, not a whitespace-only edit of the original text. Parsing can discard duplicate keys and round numbers, and serialisation can change key order, numeric spelling and string escapes.

Savings depend on the input layout and on how parsed values are re-serialised. When output is shorter, this tool reports the decrease in JavaScript string length, measured in UTF-16 code units, and the percentage saved. The comparison excludes leading and trailing whitespace in the input; it is not an exact UTF-8 byte measurement.

How to use it

  1. Paste or upload formatted JSONAny valid JSON works, whether indented or already compact.
  2. MinifyPress Minify or use Ctrl+Enter.
  3. Check the savingWhen the output is shorter than the trimmed input, the result panel reports the reduction in UTF-16 code units, labelled as characters, and the percentage saved.
  4. Copy or downloadTake the compact output straight to your clipboard or save it as a file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Indented JSON compacted

Input

{
  "id": 42,
  "tags": [
    "a",
    "b"
  ]
}

Output

{"id":42,"tags":["a","b"]}

From 48 characters to 26, a 45.8% reduction, with identical parsed data for this example.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

Whitespace inside strings is preserved
Whitespace characters within string values are preserved. A value like "hello world" keeps its spaces, but its JSON escape spelling can change: an escaped newline may be re-emitted as \n. This is parse-and-serialise minification, not a literal whitespace strip.
Minification is not compression
Minifying removes redundant characters; gzip or Brotli then compresses what remains. They compose, but the second matters more over the network: gzip already handles repetitive whitespace well, so minifying a gzipped response saves less than the raw byte count suggests. Minification helps most for data stored uncompressed, embedded in a page, or held in memory.
Key order and numbers
Keys that are valid JavaScript array indices are emitted in numeric order; other keys normally retain their input order. Numbers are re-emitted from their parsed values, so 1.0 becomes 1 and 1e3 becomes 1000. These changes can shorten or lengthen a value, and are one reason output may differ from a naive whitespace strip.

Limitations


  • Cannot minify invalid JSON; the document must parse first.
  • Savings on gzipped responses are much smaller than the raw character count implies.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Does minifying change my data?
It can. JSON.parse keeps only the last duplicate key and uses JavaScript IEEE 754 doubles, so large integers and high-precision decimals can be rounded. Numbers outside the finite range become null when serialised. Key order, numeric spelling and string escapes can also change; use strings for values that require exact numeric precision.
Should I minify if my server already uses gzip?
The extra benefit is modest, because gzip compresses repetitive whitespace efficiently. Minification is most worthwhile for JSON stored uncompressed, inlined into HTML, or kept in memory or a database.
Can I get the formatting back?
The JSON Formatter can restore a readable layout at a chosen indent width, but not the original whitespace, escape spelling, duplicate keys or numeric precision lost during parsing.