Three levels of compression
| Level | What it does | Changes the data? |
|---|---|---|
| Safe | Removes all whitespace outside strings | No |
| Balanced | Safe, plus shorter number text: 1.50 becomes 1.5 and 1E+05 becomes 1e5 | No. The values are equal |
| Maximum | Balanced, plus removing null values and empty strings, arrays and objects from objects | Yes. Keys disappear |
You can also tick each option yourself, and round decimals to a number of places. Rounding changes the data too.
What the data-changing options do
- Remove null values. A key whose value is null is removed from its object. Items inside arrays are never removed, because that would shift the positions of the other items.
- Remove empty values. Removes keys whose value is "", [] or {}. This works from the inside out, so an object that becomes empty is removed too.
- Round decimals. Limits numbers that have a decimal point or exponent to a number of places, and drops trailing zeros. Useful for coordinates and prices with float noise such as 0.30000000000000004.
Use these only when the receiver treats a missing key and null alike. Many APIs do not: a missing key can mean keep the old value, while null can mean clear it.
How to compress JSON
- Paste the JSON or open a file.
- Choose a level. Safe never changes the data. Balanced shortens number text. Maximum removes empty data.
- Optionally set a size budget in KB, to see whether the result fits a limit such as a cookie or a payload cap.
- Check the bytes saved and the gzip size, then copy or download the result.
Which level should I use?
- Safe for configuration, data you do not own, and anything you are unsure about.
- Balanced for numbers written by a program, such as 1.50 or 1E+05.
- Maximum only for data you control end to end, where you know that a missing key and a null value mean the same thing.
Typical size limits
| Where | Limit |
|---|---|
| Browser cookie | About 4 KB per cookie |
| URL | 2 KB is a safe limit for older systems |
| Amazon DynamoDB item | 400 KB |
| Local storage | About 5 MB per origin in most browsers |
Example: Maximum level
{"id": 7, "price": 19.50, "coupon": null, "notes": "", "tags": [], "stock": 1.0E+2}
becomes
{"id":7,"price":19.5,"stock":1.0e2}
Other ways to make JSON smaller
- Return fewer fields. Let clients ask for only what they need, with a fields parameter or GraphQL.
- Paginate. Send 50 records, not 5,000.
- Send columns, not rows. For a table with many rows, one array per column avoids repeating every key in every row.
- Shorten key names. Saves bytes but hurts readability and changes your format. Gzip already handles repeated keys well, so the gain is small.
- Use a binary format such as MessagePack or CBOR when both sides support it.
Size budget and gzip
Enter a size budget in KB and the tool tells you whether the result fits. It also shows the gzip size, which is what a browser downloads when the server compresses responses. If you control the server, turn on gzip or Brotli first: it usually saves more than any change to the JSON text.
Compress or minify?
The Safe level is the same as the JSON minifier. This page adds the optional steps that remove data. For the full picture, including HTTP compression, read the JSON minification guide.
Your JSON is processed in your browser and is not uploaded. See also the JSON validator and the JSON formatter.