What is a JSON minifier?
A JSON minifier removes every character that a parser does not need: the line breaks, the indentation and the spaces after colons and commas. The data stays exactly the same, only the text gets shorter. A pretty-printed configuration of 40 lines becomes one long line that you can store in an environment variable, a database column, a query string or a single line of a log file.
Minifying is the opposite of formatting. Developers format JSON to read it and minify it to ship it: an API response, a payload that goes into a message queue, a package.json snippet pasted into a CI variable, or a fixture that has to fit in one line of a CSV. Because the tool has to read the document before it prints it again, it also tells you when the JSON is broken, with the line and the column where reading stopped.
Two details make this minifier safer than a quick JSON.stringify(JSON.parse(text)) in the console. First, numbers keep the digits you wrote: an id such as 12345678901234567890 is not rounded, and 19.90 is not turned into 19.9. Second, it reads relaxed JSON, so a file with comments, single quotes or trailing commas can be cleaned into standard JSON in one step. Everything runs in your browser; the text you paste is not uploaded or stored.
How to minify JSON online
- Paste your JSON in the input box. The page opens with a small example already loaded, so you can see the result before pasting anything; use the clear button to empty the box and the example button to bring it back.
- The minified JSON appears below as you type, after a short pause. There is nothing to configure: no options, no button to press.
- Look at the size note next to the result title. It says how many characters the minified text saves compared with what you pasted, which is a quick way to know whether it was worth it.
- If the text is not valid JSON, a red message names the line and the column. Fix that spot and the result appears again.
- Press the copy button above the result and paste the single line where you need it.
The tool never reorders keys and never changes values, so the minified text can be compared with the original by JSON diff if you want to be sure. To go the other way and make a one-line payload readable, use the JSON formatter.
Examples
The default example
Input:
{
"hello": [
"world"
]
}Output, 9 characters smaller:
{"hello":["world"]}An API response
Input:
{
"user": {"name": "Ana", "id": 42},
"tags": ["a", "b"],
"active": true
}Output:
{"user":{"name":"Ana","id":42},"tags":["a","b"],"active":true}A config file with comments, single quotes and a trailing comma
A strict parser rejects this text. The minifier accepts it, drops the comment and prints standard JSON:
{
// retry policy
retries: 3, 'host': "a.local", list: [1, 2,],
}{"retries":3,"host":"a.local","list":[1,2]}Numbers that JavaScript would change
Input: {"orderId": 12345678901234567890, "price": 19.90, "ratio": 1e3}. Output, with every number as written:
{"orderId":12345678901234567890,"price":19.90,"ratio":1e3}JSON.stringify(JSON.parse(text)) in a browser console gives {"orderId":12345678901234567000,"price":19.9,"ratio":1000}: the id lost its last digits. For a database key or an order number that is a real bug.
Common errors and how to fix them
- Invalid JSON at line 1, column 9 for
{"a": 1,, "b": 2}: two commas in a row. Delete one of them. - Invalid JSON at line 1, column 8 for
{"a": 1: the text ends before the closing brace. You probably copied only part of the document; copy it again from the start to the last}or]. - Invalid JSON at line 1, column 13 for
{"price": 1,5}: JSON writes decimals with a dot, so use1.5. A comma ends the value. - Invalid JSON because of
undefinedorNaN: these are JavaScript values, not JSON. Replace them withnullor a number. - The result still has
\nand\"everywhere: the JSON was stored inside a string. Unescape it first with the JSON formatter, which has an option for that, then minify.
Frequently asked questions
Does minifying JSON change the data?
No. Only the white space between tokens is removed. Keys, values, order of keys and order of array items stay as they were. Spaces inside strings are kept, so "a b" still has two spaces.
How much smaller will my JSON be?
It depends on how much indentation the original has. Deeply nested, pretty-printed files save the most; a document that is already one line saves nothing. The tool shows the exact number of characters saved for your text.
Is minified JSON the same as compressed JSON?
No. Minifying removes optional characters and the result is still plain JSON that any parser reads. Compression, such as gzip or brotli on an HTTP response, encodes the bytes and has to be decoded. The two work together: minified JSON compresses a little better.
Is it safe to paste private JSON here?
Yes. The work is done in your browser and nothing is sent to a server. Do not paste real secrets into any online tool you do not trust, but this page does not transmit what you type.
Can I minify JSON with comments?
Yes. Comments and trailing commas are accepted when reading and do not appear in the output, because standard JSON has neither. That is useful to turn a commented config file into valid JSON.
How do I minify other formats?
For HTML, CSS or JavaScript use the code minifier. For YAML, see the YAML formatter.
How to minify JSON in code
JavaScript
JSON.stringify without a third argument prints no white space. Remember that it can round big numbers.
const text = '{\n "user": { "name": "Ana", "id": 42 }\n}';
const minified = JSON.stringify(JSON.parse(text));
console.log(minified); // {"user":{"name":"Ana","id":42}}Python
The default separators of json.dumps include spaces; pass compact ones.
import json
data = json.loads('{\n "user": { "name": "Ana", "id": 42 }\n}')
print(json.dumps(data, separators=(",", ":"), ensure_ascii=False))Go
json.Compact removes the white space without decoding into a struct.
var out bytes.Buffer
err := json.Compact(&out, []byte("{\n \"user\": { \"id\": 42 }\n}"))
if err != nil {
log.Fatal(err)
}
fmt.Println(out.String()) // {"user":{"id":42}}Bash
jq -c prints compact JSON from a file or a pipe.
jq -c . data.json
echo '{ "a": [1, 2] }' | jq -c .