Skip to contentSkip to the inputSkip to the result

Minify JSON

Remove optional whitespace from JSON.

Loading tool

Instructions

Minify JSON

How to use

  1. Paste valid JSON and generate a compact representation.

Supported input

  • Only whitespace outside strings is removed, so numbers and strings stay exactly as written.
  • The result can be wrapped as one string value.
  • Invalid syntax is rejected.

Input example

{ "a": 1 }

Result example

{"a":1}

Troubleshooting

  • Check required inputs, numeric ranges and the selected conversion direction.

How it works

  • Remove optional whitespace from JSON.

One-line JSON: where it is needed and what it really saves

Places that want JSON on a single line

  • The body of a curl -d request or an HTTP client field, pasted in one go
  • An environment variable or a .env entry, where one value has to fit on one line
  • Log files in JSON Lines (NDJSON), one record per line so tools can stream them
  • A text column in a database or a key in browser storage that holds JSON as a string

Measured: one order, then two hundred

A single order record indented with two spaces, with an order number, a customer called 김민지 in 부산, two line items, a paid flag and a note, came to 291 bytes. Minified it was 184 bytes. All 107 bytes saved were indentation, line breaks and the space after each colon. The Korean names cost three bytes per character in UTF-8 before and after; minifying does not touch them.

Two hundred records of a similar shape in one array measured 19,745 bytes indented and 12,544 bytes minified, about 36% less. The shorter and more deeply nested the records, the larger the share of a pretty-printed file that is just indentation, so the saving grows.

Next to gzip and Brotli, the gap shrinks

Most web servers compress responses on the way out, and repeated spaces are exactly what compressors are good at. Compressing those 200 records with Node’s zlib at its default settings gave 2,320 bytes for the indented file and 1,965 for the minified one with gzip, and 1,279 against 1,222 with Brotli.

So for an API response that is sent compressed, stripping whitespace saved only a few hundred bytes in this sample, against more than 7,000 before compression. It still pays where no transfer compression steps in: a length limit on an environment variable, a log line, a database field, or a payload that some other system stores as is.

Building a JSON Lines file

JSON Lines is UTF-8 text with one valid JSON value per line, separated by \n. A record must not contain a raw line break, which minifying guarantees: a line break inside a string is already written as the two characters \n, so it stays inside the line. With one record per line, wc -l counts records, every line grep finds is a whole record, and appending a record means appending a line.

The tool takes one JSON value at a time. Paste two lines that are already JSON Lines, {"a":1} and then {"a":2}, and it reports a syntax error at line 2, column 1. Wrap several records in an array and you get one line, [{"a":1},{"a":2}]; for one record per line, minify each record on its own.

When to wrap the result as a string

Minifying {"msg": "say \"hi\"", "path": "C:\\temp"} gives {"msg":"say \"hi\"","path":"C:\\temp"}. With Wrap as a string, every quote and backslash is escaped once more and the whole thing is quoted: "{\"msg\":\"say \\\"hi\\\"\",\"path\":\"C:\\\\temp\"}". The doubled backslashes are correct, not a bug.

Use that form when JSON has to sit inside a string field of other JSON, or inside a string literal in JavaScript or Java source. For a shell command, use the unwrapped result inside single quotes instead; send the wrapped one with curl and the server receives a single string, not an object.

Checked

Frequently asked questions

How much smaller does minified JSON get?

It shrinks by the space the indentation and line breaks took. The tool shows input and output bytes and the saving. For example, { "a": 1 } (10 bytes) becomes {"a":1} (7 bytes).

Does minifying change the data?

No. Only whitespace outside strings is removed, so 1.0, 1e3, very large integers and the key order stay as written. Set Output to Wrap as a string to turn the minified JSON into one string value such as "{\"a\":1}"; paste JSON wrapped in a string and a button unwraps it.

Is this the same as gzip or ZIP?

No. It only removes optional whitespace, and the result is still plain JSON text. Spaces inside strings and escapes such as \n are part of the values and stay.