JSON minify

What is a Json Minify?

Pretty-printed JSON is great for reading but wastes bytes on indentation, spaces and line breaks. Minifying removes all of that without changing the data, producing the smallest valid JSON text. Smaller JSON means faster API responses, smaller files and fewer bytes in local storage, cookies or URL parameters.

How to use it

  1. Paste formatted JSON.
  2. Minify it. Invalid JSON is reported instead of being silently changed.
  3. Copy the compact result.

Example

Input (98 bytes):

{
  'id': 42,
  'name': 'Widget',
  'tags': [
    'blue',
    'small'
  ]
}

Output (51 bytes):

{'id':42,'name':'Widget','tags':['blue','small']}

(Real JSON uses double quotes.) About half the size, with identical data.

What minification does and does not change

  • Whitespace outside strings is removed.
  • Whitespace inside string values is kept exactly.
  • Key order, values and types are unchanged.

Is it worth it?

For API responses, gzip or Brotli compression already removes most of the cost of whitespace, so minifying adds a smaller extra gain, but it is free to do and most frameworks already send minified JSON by default. Minification matters more where compression is not applied: localStorage, cookies, message queues, database columns and query strings.

In code

  • JavaScript: JSON.stringify(obj) produces minified JSON by default.
  • Python: json.dumps(obj, separators=(',', ':')).
  • Command line: jq -c . file.json.

Frequently Asked Questions

Does minifying JSON change the data?

No. Only whitespace outside of strings is removed. Values, types and key order stay the same.

How much smaller does JSON get?

Often 20 to 50 percent, depending on how deeply it was indented.

Is minifying needed if I use gzip?

Compression removes most of the overhead, but minifying still helps for storage, cookies and places where compression is not applied.

How do I minify JSON from the command line?

Use jq -c . followed by the file name.