JSON Minifier
Minify JSON to the smallest possible size for APIs and config files.
Written by Anil Gautam · Updated
How much does minifying JSON save?
The minifier runs JSON.parse on your text and JSON.stringify on the result, which drops every space, tab and line break that sits outside a string. Text inside strings is kept exactly, spaces included. Under the output, three cards compare UTF-8 byte counts and give the saving as a whole percentage. For the sample object in the input box that is 59 bytes down to 46, a saving of 22 percent.
Indentation decides most of the saving. A small record with two users, each with an id, name, email and active flag, minifies to 140 bytes whatever layout it starts in. Indented with four spaces it is 300 bytes, so 53 percent is saved; with two spaces it is 232 bytes and 40 percent; with tabs it is 198 bytes and 29 percent. Deep nesting adds indentation and raises the percentage, while long keys and long string values lower it, because every character inside quotes is kept. Input that is already minified shows 0 B saved.
Does minifying JSON change the data?
Because the text is parsed and written out again, some values come back in a different form. Numbers are normalized: 1.50 becomes 1.5, 1e3 becomes 1000, -0 becomes 0, and 1e400, which is too large for a JavaScript number, becomes null. Integers past 9007199254740991 can lose digits, so 12345678901234567890 comes out as 12345678901234567000. Escapes are resolved, so "caf\u00e9" is written as "café" and "a\/b" as "a/b".
Object keys that look like whole numbers move to the front in ascending order, because that is how JavaScript orders object keys: {"b": 1, "2": "two", "a": 3, "1": "one"} comes out as {"1":"one","2":"two","b":1,"a":3}. A key that appears twice keeps only its last value. For most programs the data means the same afterwards, but compare the output when key order, number formatting or long IDs matter to whatever reads the file.
The result is a single line with no line break at the end, so add one after pasting if your editor or linter expects files to end with a newline. Invalid input puts the parser's error message in the output box, labeled Error, and hides the size cards. The JSON Validator reports the same error and, once the input parses, shows it formatted with two-space indentation.