What the JSON Minifier does
The JSON Minifier deletes the whitespace that JSON permits between its tokens and writes the document as one line. Nothing else changes: each string, number and key is copied character for character from your input. It reads the input against RFC 8259 (opens in a new tab) first, so a minified result is always valid JSON.
How to minify JSON
- Paste the JSON, or open or drop a file. Input below 1 MB is minified while you type; for bigger input, press Minify or Ctrl+Enter.
- For a config file with comments or trailing commas, turn on Allow comments (JSONC).
- Look at the table under the output: it compares the sizes before and after minifying, plain and gzipped.
- Copy the single line, or download it as a
.min.jsonfile.
Examples
Input
{ "city": "New York", "zip": "10001", "tags": [ "east", "coast" ] }
Output
{"city":"New York","zip":"10001","tags":["east","coast"]}
Input
{
/* feature flags */
"beta": false,
"regions": ["eu", "us",],
}
Output
{"beta":false,"regions":["eu","us"]}
Input
{"ratio": 1.0E+2, "big": 9007199254740993}
Output
{"ratio":1.0E+2,"big":9007199254740993}
Options
| Option | Values | Default | When to change it |
|---|---|---|---|
| Allow comments (JSONC) | On, Off | Off | Turn it on for input with // or /* */ comments or with trailing commas. Both are removed, each with a note under Problems, and the output is plain JSON that any parser accepts. |
Common errors and fixes
| Code | What it means | How to fix it |
|---|---|---|
JSON_Error | The input is JSONC, such as a settings file with comments, while Allow comments (JSONC) is off. | Turn the option on; the minifier then removes the comments for you. |
JSON_Error | A comma stands after the last item of a list or the last member of an object. | With Allow comments (JSONC) on, the minifier drops it; otherwise delete it in the input. |
JSON_Error | The input holds several JSON values, such as a log with one record per line. | Minify one record at a time. Each minified record is already a valid line of a JSON Lines file. |
JSON_Warning | One object names the same key twice. Minifying keeps both, in their order. | Delete the member that the receiving program should not see. |
Other syntax errors stop the minifier too. The JSON Formatter explains each of them, with examples of the fix.
Minifying versus gzip
Minifying and compression shrink JSON in different ways. Minifying deletes characters that carry no data. Gzip, which web servers often apply to their responses, encodes repeated patterns compactly, and runs of indentation are just such patterns. A document that loses a third of its size when minified may therefore save far less once both versions are gzipped. The table under the output measures both cases for your own data.
Minifying still pays where nothing compresses the data on the way: values kept in the browser's local storage or in a cookie, an environment variable, a message to a queue with a size limit, or a request body sent without compression.
What minifying removes, and what it keeps
JSON defines four whitespace characters that may sit between tokens: space, tab, line feed and carriage return. They only lay the document out, so deleting them leaves the data as it was. Everything inside a value stays: the space in "New York" belongs to the string, an escape such as \n keeps its two characters, and 1.0E+2 is not rewritten as 100. A key that appears twice in an object stays twice, in its place, and the minifier warns about it.
JSON on a single line
One-line JSON goes where line breaks would get in the way: an environment variable, a command-line argument, a single log line, or a record in a JSON Lines file, where every line is a document of its own. Minifying is also a quick way to hand a commented configuration to a system that accepts only strict JSON, since the output never contains a comment.