JSON Minifier
Strip whitespace from JSON and get a compact, valid single line, minified as you paste.
Minify JSON Online
Pretty-printed JSON is written for people; the indentation and line breaks mean nothing to a parser. Minifying removes them so the same data takes fewer bytes and fits on one line, which is handy for environment variables, command-line arguments, log lines and request bodies.
This page opens the JSON Formatter set to minify as soon as you paste. The document is parsed first, so you only ever copy valid JSON.
What exactly is removed
- Indentation spaces and tabs.
- Line breaks between keys and array items.
- Spaces after
:and,. - Nothing inside quoted strings:
"New York"keeps its space.
When minifying helps
| Situation | Why one line helps |
|---|---|
| Environment variables and secrets managers | Many expect a single-line value |
| curl and CLI arguments | No escaping of line breaks in the shell |
| Structured logs (JSON Lines) | One record per line is the format |
| Storing JSON in a database column | Fewer bytes per row |
| Static JSON files served by a website | Smaller downloads, even before compression |
Minify versus gzip
For JSON served over HTTP, compression does most of the work: gzip and Brotli are very good at squeezing repeated whitespace. Minifying still helps a little and costs nothing, but do not expect a 40 percent smaller text to mean a 40 percent faster response. Where minifying clearly wins is anywhere compression is not applied, such as local storage, database fields and message queues.
Minifying in code
- JavaScript:
JSON.stringify(JSON.parse(text)) - Python:
json.dumps(obj, separators=(',', ':')) - jq:
jq -c . file.json - PHP:
json_encode(json_decode($text))
Need to find a syntax error first? JSON Validator explains what is wrong and where.