JSON to One Line

Collapse JSON into a single minified line, removing all unnecessary whitespace and newlines.

JSON to one line converts multi-line, indented JSON into a compact single-line string by removing all non-essential whitespace. This is essential for environment variables, shell scripts, command-line arguments, and any context where line breaks in a JSON string would cause a parse error. The output is identical to what JSON minification produces.

starstarstarstarstar
4.8· 891 ratings
shieldRuns entirely in your browser
cloud_offNo data stored or uploaded
volunteer_activismFree forever
1234567891011121314151617181920
1234567891011121314151617181920

What Is JSON to One Line?

JSON to One Line collapses a multi-line, indented JSON document into a single line by removing all non-essential whitespace — newlines, spaces between tokens, and indentation — while keeping the data and structure fully intact.

The result is identical to JSON minification: a compact, single-line string. This format is required in many situations where JSON must be passed as a string argument, environment variable, or inline value without line breaks causing parse errors. To expand it again, use our JSON Pretty Print or JSON Formatter.

Common Use Cases

  • check_circleCompress JSON for use as a single-line environment variable
  • check_circleFlatten JSON for embedding in a shell script or command-line argument
  • check_circleProduce a one-line JSON string for a Content-Type: application/json header
  • check_circleCollapse JSON for storing as a single value in a SQL column
  • check_circleConvert multi-line JSON to inline format for a configuration value
  • check_circlePrepare JSON for embedding inside a string in another JSON document

How to Convert JSON to One Line – Step by Step

1

Paste your JSON

Copy multi-line, indented JSON from an editor, API response, or config file and paste it into the input panel on the left.

2

Click Collapse

Press the Collapse button. The tool parses, validates, and collapses your JSON to a single line instantly in your browser.

3

Copy the output

Click Copy to grab the single-line JSON string, ready to paste into an environment variable, shell script, or config value.

When Do You Need JSON on One Line?

Single-line JSON is required in contexts that don't support multi-line strings — here are the most common ones.

terminal

Environment Variables

Environment variables must be single-line values. Multi-line JSON breaks shell variable assignment and causes parse errors in dotenv files.

code

Shell Scripts & CLI Arguments

Passing JSON as a -d or --data argument to curl or other CLI tools requires the JSON on a single line to avoid shell interpretation issues.

data_object

Inline YAML Values

When embedding JSON inside a YAML file as a string value, the JSON must be on one line to avoid YAML multi-line parsing conflicts.

storage

Database JSON Columns

Some database UIs, migration scripts, or query strings require JSON values to be expressed as a single-line string literal.

settings

Config File Values

Configuration systems that don't support multi-line strings require compact JSON. One-line format ensures compatibility across all config parsers.

link

HTTP Headers & URLs

JSON embedded in custom HTTP headers or URL query parameters must be on a single line — multi-line values are rejected by most HTTP parsers.

JSON to One Line vs JSON Minify vs JSON Pretty Print

All three tools manipulate whitespace — choose based on what you need the output for.

FeatureJSON to One LineJSON MinifyJSON Pretty Print
OutputSingle compact lineSingle compact lineMulti-line indented
Shows size savings✗ No✓ Yes✗ No
Human readable✗ No✗ No✓ Yes
Safe for env vars✓ Yes✓ Yes✗ No
Output is smaller✓ Yes✓ Yes✗ Larger
Best forEnv vars, CLI, configAPIs, storage, transmissionDebugging, code review
wrap_text

Single Line Output

The entire JSON document is collapsed to one line — no newlines, no indentation — ready to paste anywhere a line break would cause a problem.

verified

Data Preserved

Only whitespace is removed. All keys, values, arrays, objects, and nesting relationships remain exactly the same as in the original.

bolt

Instant Conversion

Conversion is immediate. Paste your formatted JSON and get the one-line version in milliseconds, entirely in your browser.

verified

JSON Has Errors? Validate First

The tool requires valid JSON. If it fails, use our JSON Validator to find the error, or our JSON fix guide for step-by-step repairs on trailing commas, single quotes, and other common mistakes.

Validate JSON

Frequently Asked Questions

Is JSON to One Line the same as minification?

Yes. Both operations produce the same result — the most compact valid JSON string with all unnecessary whitespace removed on a single line. JSON Minify additionally shows byte and percentage savings.

Why would I need JSON on a single line?

Some systems cannot handle multi-line strings — shell variables, YAML inline values, HTTP header values, or CLI arguments. One-line JSON avoids parsing errors in these contexts.

Can I reverse this and expand the JSON again?

Yes. Use our JSON Formatter or JSON Pretty Print tool to expand a one-line JSON string back into a readable, multi-line indented format.

Does this work with JSON arrays at the root level?

Yes. The tool handles any valid JSON — objects, arrays, strings, numbers, booleans, and null — regardless of what the root element is.

Does collapsing JSON to one line change the data?

No. Only whitespace is removed — all keys, values, arrays, objects, and nesting relationships are preserved exactly. The output is semantically identical to the input.

Is this tool free?

Completely free with no account required. All conversion runs locally in your browser — no data is uploaded to any server.

Go Deeper

Related JSON Learning Resources

verified_user

About This Tool

Built by OpenFormatter · Last updated

wrap_textGuaranteed single-line output
lock100% browser-based — zero uploads
starFree forever, no account needed
JSON to One Line – Compact JSON to Single Line Free