Skip to content

Convert JSON to one line

Collapse a formatted JSON document onto a single line, with or without spaces after colons and commas, for logs, env vars and shell arguments.

  • Runs in your browser
  • Files are never uploaded
  • Free, no account
JSON to one line
Collapse a formatted document onto a single line for a log field, an environment variable or a shell argument.
Your JSON never leaves this tab — check it yourself—

Starting the network probe…

The counter above wraps fetch, XMLHttpRequest and navigator.sendBeacon in this tab and counts every call. It does not block anything — it just reports.

Two ways to verify independently

  1. Turn off Wi-Fi or enable airplane mode, then use the tool. It keeps working, because the page is already fully loaded.
  2. Open your browser devtools, switch to the Network tab, clear it, and run the tool. No new row appears.

Why this matters

In 2025 researchers found that popular online formatters had retained tens of thousands of user-submitted snippets — JSONFormatter.org and CodeBeautify together exposed roughly 80,000 saved documents, many containing live cloud credentials, private keys and internal database connection strings, because “format this” quietly meant “upload this”. A separate incident exposed roughly 3.5 million user PDFs on a document-conversion service. The only structural fix is not sending the data in the first place: this site is served under a Content-Security-Policy whose connect-src contains no third-party origin, so a request off this device cannot be made even by accident.

One line, still readable

Minifying and collapsing to one line are not the same operation. Minifying removes every optional byte, which produces {"id":42,"name":"Ada"}. Collapsing keeps a single space after each colon and comma, producing {"id": 42, "name": "Ada"} — still one line, still valid, and far easier to read when it appears in a log viewer or a terminal at 2am. Turn the spacing switch off and the two are identical.

Where a single line is required

Log lines

Every structured logging pipeline — journald, Docker’s json-file driver, Fluent Bit, Vector, CloudWatch — treats a newline as a record boundary. A pretty-printed JSON payload written to a log becomes fifteen unrelated records, none of which parse, and a search for the request ID finds only the line it happened to appear on. One line per event is not a style preference, it is what makes the log queryable.

Environment variables

A newline inside an env var is possible but awkward in nearly every runtime: Docker --env, systemd Environment=, and most CI secret stores either reject it or require escaping. Collapsing first removes the problem.

Command-line arguments

A one-line payload can be wrapped in single quotes and passed straight to curl: curl -d '{"a": 1}' -H 'content-type: application/json' …. If the JSON itself contains a single quote, use JSON escape to produce a fully escaped literal instead, or write the body to a file and use -d @file.json.

Spreadsheet cells and issue trackers

Pasting multi-line JSON into a spreadsheet cell splits it across rows. One line pastes as one cell.

What happens to newlines inside strings

They stay escaped. A string containing a real line break is already invalid JSON, so anything you paste that parses has its newlines stored as the two-character sequence \n. Collapsing does not touch string contents, so a multi-line message field survives intact — it is only the layout between tokens that changes.

Going back

Nothing is lost, so pasting the one-line result into the JSON formatter restores an indented document. Key order is preserved unless you asked for it to be sorted, so the round trip is faithful.

Questions

How is this different from minifying?

Minifying removes every optional byte. One-line mode can keep a space after each colon and comma, which is still one line but stays readable when it appears in a log viewer or a terminal. Turn the spacing switch off and the two produce identical output.

Why do I need JSON on one line?

Structured log lines have to be one line or the log shipper splits them into separate records. Environment variables cannot contain a raw newline without escaping. And a JSON argument passed to a CLI is far easier to quote correctly when it has no line breaks.

How do I get this into a shell command safely?

Wrap it in single quotes for bash and zsh: `curl -d '{"a": 1}'`. If the JSON itself contains a single quote, use the Escape JSON tool to produce a fully escaped string literal instead.

Does it change any values?

No. The document is parsed and re-emitted, so numbers keep their value and strings keep their exact contents — including any newlines inside a string, which stay as the two-character escape \n and never become real line breaks.