JSON to One Line

Flatten a pretty printed document onto a single line so it fits in a shell argument, a log entry or a config value.

Multi-line JSON
Single line
Runs locally in your browser

About the JSON to One Line

Plenty of places accept JSON but only on one line: an environment variable, a Kubernetes annotation, a curl argument, a single cell in a spreadsheet, or a structured log field. Collapsing by hand is error prone because a line break inside a string must survive as \n while the ones between keys must go. This tool handles that distinction for you.

The default method parses the document and rebuilds it, which guarantees the result is valid and reports the exact position of any syntax problem before you paste something broken into a deploy. The alternative method strips whitespace that sits outside string literals without parsing, so it works on a fragment or on a file that uses a superset such as trailing commas, and it leaves everything else byte for byte identical.

Spacing controls how readable the single line is. The compact setting removes every optional space and gives the shortest possible text. The spaced setting keeps one space after each comma and colon, which stays on one line but is far easier to scan in a terminal. The status line reports the character count before and after so you can see what a config value will cost you.

Use JSON Formatter to expand the result again, and JSON Minifier when the goal is the smallest payload rather than a one line value.

How to use

  1. Paste indented JSON, or press Sample for a request body spread over several lines.
  2. Leave Method on Parse and rebuild so the output is checked for validity.
  3. Choose Space after commas and colons if the line still needs to be readable.
  4. Copy the single line, or press Swap to reopen it in the formatter.

Common questions

What happens to newlines inside my string values?
They stay, written as the escape \n. Only the formatting whitespace between tokens is removed.
When should I use "Strip whitespace only"?
When the input is a fragment or uses non standard syntax that a strict parser rejects, and you want the text collapsed without any rewriting.
Is this the same as minifying?
The compact setting produces the same bytes as the minifier. The difference is the spaced setting, which keeps the line readable, and the raw method, which never reparses your text.
Why is my one line output longer than I expected?
Escaped characters inside strings each take two characters or more. A document full of quoted paths or embedded JSON will not shrink much.