FormatterHQ

JSON to One Line

Collapse a multi-line JSON document onto a single line so it fits in an environment variable, a command-line flag or one log entry. Optionally keep light spacing for readability.

Input JSON
Output JSON
Ready.

How to use the JSON to One Line

  1. Paste or upload your formatted JSON, or click Sample.
  2. Tick Keep a space after : and , if you want the line to stay easy to read.
  3. Click Convert to One Line; the status bar shows the size before and after.
  4. Copy the single line into your .env file, shell command or config.

Convert JSON to one line

JSON to one line is the conversion you need whenever a tool treats a newline as the end of a value. Environment variables, shell arguments, Docker and CI settings, single log entries and JSON Lines records all expect the whole document on one physical line. This tool parses your JSON and writes it back without any line breaks.

Example

{
  "level": "info",
  "retry": { "max": 3, "backoff": "exp" }
}

Default output:

{"level":"info","retry":{"max":3,"backoff":"exp"}}

With Keep a space after : and , ticked:

{ "level": "info", "retry": { "max": 3, "backoff": "exp" } }

The status bar reports the change in size, for example "65 B → 60 B (8% smaller)" for the spaced version.

One line vs minify

With the option off, the result is identical to minified JSON. The difference is the goal: minifying is about saving bytes, while a one-line value mainly has to survive a line-based format. The spaced variant is often the better choice for anything a person will read again, such as a value in a .env file or a line in a runbook, because it is still compact but far easier to scan.

Typical places for single-line JSON

  • Environment variables: APP_FEATURES={"beta":true,"limit":50}. Many loaders read only up to the end of the line, so a multi-line value is cut off.
  • Command-line flags: options such as --data '{...}' are easiest to pass on one line; wrap the JSON in single quotes in a POSIX shell so the double quotes survive.
  • Log lines: structured logging writes one JSON object per line so that log shippers can split entries on newlines.
  • JSON Lines files: each record must be one line. To convert a whole array into records at once, use JSON to JSONL.

Line breaks inside values

A line break that is part of a string value is already written as the two characters \n in valid JSON, so it does not break the line. A real line break inside quotes is invalid JSON and is reported as "Unescaped line break inside string". If your value is a piece of multi-line text, turn it into an escaped string first with the JSON multiline string converter.

When you need to read a one-line document again, the JSON formatter restores the indentation. All processing is local to your browser.

Frequently asked questions

How do I put JSON in an environment variable?
Convert it to one line here, then assign it in your .env file or shell. In a shell, wrap the value in single quotes so the double quotes inside the JSON are kept.
Is JSON on one line still valid JSON?
Yes. Whitespace between tokens is optional in JSON, so the single-line version parses to exactly the same data as the formatted one.
What does "Keep a space after : and ," do?
It adds one space after every colon and comma and inside brackets, giving output like { "a": 1, "b": 2 }. The document is still on one line but is easier to read.
Why does the tool report an unescaped line break?
A string value contains a real line break instead of the \n escape. JSON does not allow that. Replace the break with \n in the source or regenerate the JSON with a proper serializer.

Last updated September 26, 2026

Related tools

JSON to PHP Array Converter Convert JSON to a PHP array literal with short [] or array() syntax, ready to paste into Laravel config files, seeders and tests. JSON to String Converter Convert JSON to a single escaped string you can paste into code, databases or other JSON documents. Choose double, single or no quotes. JSON Tree Viewer Display JSON as an expandable tree. Collapse and expand objects and arrays to understand deeply nested data structures. JSON Unflatten Rebuild nested JSON from flat dot-notation keys (a.b.c) or bracket paths (a[0].b), the reverse of JSON flatten. JSON Validator Validate JSON online and find syntax errors fast. Get the exact line and column of each problem and fix broken JSON in one click. JSON Viewer & Beautifier View JSON as a collapsible tree and beautify it at the same time. Explore nested objects and arrays without losing your place. JSON5 Formatter Format and beautify JSON5 with comments, unquoted keys and trailing commas, or convert JSON5 to strict JSON. JSON5 Validator Validate JSON5 syntax online. Check config files with comments and trailing commas and get line and column for each error. JSONL to JSON Converter Convert JSON Lines (JSONL / NDJSON) into a formatted JSON array. Invalid lines are reported with their line number. JSONPath Tester Test JSONPath expressions online against your JSON. Supports filters, wildcards, recursive descent and slices, returning values or paths. String to JSON Converter Convert an escaped JSON string back into formatted JSON. Handles quoted literals, backslash-escaped text and double-encoded JSON. JSON Graph Visualizer Visualize JSON data as a graph of connected nodes. See objects, arrays and values as a diagram of linked boxes with size badges.