JSON Viewer, Formatter & Validator · Tutorial
How to minify JSON for a config field or API request
5 min readbeginnerUpdated
Many places only accept JSON on a single line, such as environment variables, query strings, CI settings and some admin panels. This tutorial shows how to compress a readable JSON document into one line without breaking it, check how much smaller it got, and turn it back into readable form when you need to edit it again.
What you need
- The JSON Viewer, Formatter & Validator
- A formatted JSON document, such as a settings file (the Try it button loads one)
Steps
Load your formatted JSON
Paste the JSON into the left box or open the file. The status bar confirms it is valid and shows its size in bytes. Note this number so you can compare it later.
Switch the result to Minify
Above the result box, press Minify. The output collapses into a single line with every optional space and line break removed. The values themselves are unchanged. Only whitespace outside strings is removed, so text inside quotes keeps its spaces.
{"appName":"field-notes","version":"2.3.1","features":{"offlineMode":true}}Compare the size
Look at the byte count in the status bar again. For typical indented files the minified version is 20–40% smaller. The deeper the nesting, the bigger the saving, because indentation adds more spaces on every level.
Sort keys for stable output (optional)
If the minified value is stored somewhere and compared over time, such as in version control or a deployment setting, tick Sort keys A–Z. The same data then always produces exactly the same line, so changes stand out clearly.
Copy it into the target field
Press Copy and paste it where it is needed. If the field is an environment variable in a shell, wrap the whole value in single quotes so the shell does not interpret the double quotes inside it.
Expand it again to edit
To change the config later, paste the single line back into the tool and press Format. You get the readable version back, ready to edit, and can minify it again afterwards.
Try it yourself
Opens the JSON Viewer, Formatter & Validator with this tutorial's sample loaded.
Common mistakes
- Minifying by deleting line breaks by hand
- Removing line breaks in a text editor can join words inside strings or leave stray spaces. The tool understands JSON structure and only removes whitespace that is safe to remove.
- Forgetting to escape for the shell
- In Bash and similar shells, an unquoted JSON value is split on spaces and its double quotes are removed. Use
export SETTINGS='...'with single quotes around the minified JSON. - Expecting minify to remove data
- Minifying does not drop unused fields or shorten values. If the result is still too large, you need to remove properties from the data itself.
Next steps
Go back to the JSON Viewer, Formatter & Validator, or keep going with one of these:
FAQ
Is minified JSON still valid JSON?
Yes. Whitespace between tokens is optional in JSON, so any parser reads the minified and formatted versions as identical data.
Does minifying make an API faster?
It reduces the number of bytes sent. Most servers also compress responses with gzip or Brotli, which already shrinks whitespace very well, so the gain is largest where compression is not applied.