About JSON Minify
JSON Minify: remove whitespace from JSON.
Your document never leaves the browser.
- no sign-up
- works offline
Put a JSON document on one line with a single press, without sending it away. For readable indentation and sorting, use the JSON Formatter; for input that will not parse, use JSON Repair; for the complete workspace, open the JSON editor.
What JSON minifying removes
Before
{
"id": 12345678901234567890,
"label": "two spaces",
"price": 1.0
}Minified
{"id":12345678901234567890,"label":"two spaces","price":1.0}JSON grammar allows whitespace between tokens and gives it no meaning. The spaces, tabs, line feeds and carriage returns around brackets, braces, commas and colons are there for people reading the file. Minifying deletes every one of them and leaves the tokens in the same order, so the whole document sits on one line. A conforming parser reads the minified text into exactly the same data as the indented original.
Paste or open JSON on this page, then press Minify under Transform in the pane toolbar, or find Minify in the command palette. The rewrite is one step in the undo history. Minify needs a document that parses, because stripping whitespace from broken text would hide where it is broken; when the status bar says Invalid JSON, the button is unavailable and points you to Repair, which fixes common near-JSON first and names each change.
Whitespace inside a string is part of its value, so it stays. In the example above the label keeps both of its spaces, and an escaped newline written as a backslash and an n stays as those two characters instead of turning into a real line break. Only the gaps between tokens go. The same rule protects tabs and spaces in keys, which JSON allows even though they are rare.
Big numbers stay exactly as written
The quickest way to write a minifier in JavaScript is to parse the text and stringify it again, and many online tools do exactly that. The round trip converts every number to a double-precision float, which holds integers exactly only up to 9,007,199,254,740,991. The twenty-digit id in the example would come back as 12345678901234567000, which identifies a different record, and nothing would warn you. The same round trip rewrites 1.0 as 1, keeps only the last of any duplicate keys and moves integer-like keys to the front of their object.
This minifier never makes that round trip. It parses the text into a syntax tree and writes each number, string and key back out as the characters you supplied. A nineteen-digit database id, a long decimal price, 1e400, -0 and 1.0 all survive, and so do escape sequences inside strings: an escaped slash or a Unicode escape keeps its spelling instead of being decoded into a second, equivalent form. Duplicate keys stay where they were, in their original order.
That makes the output safe to diff and safe to hand to a system that reads 64-bit integers natively. It also makes Minify and Format exact inverses for layout. Minify, format, then minify again, and you get back byte for byte the text the first Minify produced.
JSON minify and gzip solve different problems
Minifying and compressing both make JSON smaller, but at different layers. Minify produces text that is still JSON: any parser reads it, you can paste it into a request body or a configuration field, and it stays small wherever it is stored. Gzip and Brotli are encodings applied in transit, usually by the web server, and the receiver has to decode them before a parser sees anything.
Compression is very good at squeezing out repeated whitespace, so the saving from minifying shrinks once a response is gzipped. Indentation that makes up a large share of a file on disk may cost only a few percent after compression. Minify still pays wherever compression does not reach: a value stored in a database column or in browser storage, an environment variable, a message on a queue with a size limit, a fixture committed to a repository, or JSON embedded as a string inside another document. The usual answer is both: minify what you store and send, and let the server compress the wire.
The status bar shows the size of the document in UTF-8 bytes, so press Minify and read the new figure to see what the whitespace was costing. Undo, and the indented version returns with the size it had before.
Format JSON again when people need to read it
Minified JSON is written for machines. When a person needs to review it, debug a response or compare two versions, turn it back into indented text. The JSON Formatter page opens the same editor with two panes side by side, and offers Format with two, three or four spaces or a tab, plus Sort keys for objects whose members arrive in different orders. Neither layout touches a token, so you can switch between them as often as you like.
You do not have to leave this page for that. Format sits beside Minify under Transform, and Tree view reads a single-line document as easily as an indented one, because it draws the structure rather than the text. When you convert YAML, XML or CSV on the Convert page, its Minify option writes the JSON result on one line in the first place.
Format and beautify JSON again with the indent you choose.
Minify a large file without uploading it
Minifying runs in JavaScript inside this tab, on a parser the site ships with the page. Open a file from disk or drag it onto the editor and it is read through the browser, not sent anywhere; From URL fetches the address you give it straight from your browser. API keys, customer records and unreleased configuration therefore stay on your own machine, and Minify keeps working once the page has loaded, connected or not.
Large documents follow the same path. Code view and the text transforms work on the whole file. When a document is too large for the browser to keep across a reload, the status bar marks it as not saved instead of claiming otherwise, and the minified text stays in the open tab for you to copy or save.