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.
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
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.
Click Collapse
Press the Collapse button. The tool parses, validates, and collapses your JSON to a single line instantly in your browser.
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.
Environment Variables
Environment variables must be single-line values. Multi-line JSON breaks shell variable assignment and causes parse errors in dotenv files.
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.
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.
Database JSON Columns
Some database UIs, migration scripts, or query strings require JSON values to be expressed as a single-line string literal.
Config File Values
Configuration systems that don't support multi-line strings require compact JSON. One-line format ensures compatibility across all config parsers.
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.
| Feature | JSON to One Line | JSON Minify | JSON Pretty Print |
|---|---|---|---|
| Output | Single compact line | Single compact line | Multi-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 for | Env vars, CLI, config | APIs, storage, transmission | Debugging, code review |
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.
Data Preserved
Only whitespace is removed. All keys, values, arrays, objects, and nesting relationships remain exactly the same as in the original.
Instant Conversion
Conversion is immediate. Paste your formatted JSON and get the one-line version in milliseconds, entirely in your browser.
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.
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
Minify JSON API Responses
How to shrink JSON payloads programmatically in Express, Python, Go, and via CLI tools like jq.
JSON Format Explained
Deep dive into JSON syntax, whitespace rules, data types, and the RFC 8259 specification.
Fix Invalid JSON
Step-by-step fixes for trailing commas, single quotes, comments, and other common JSON errors.
Remove JSON Comments
JSON does not allow comments — here is how to strip them before minifying or collapsing.
About This Tool
Built by OpenFormatter · Last updated
Developer Insights
From the Blog
How to Use a JSON Formatter: The Complete Guide
Everything about JSON formatters — how they work, when to use them, and what to look for in a good online JSON beautifier.
Why JSON Formatting Matters More Than You Think
How proper JSON structure prevents production bugs, improves debugging, and makes code reviews faster.
Why Client-Side Data Processing Matters for Privacy
How processing JSON entirely in the browser protects sensitive data and avoids unnecessary server round-trips.
Part of the JSON Toolkit
Explore All JSON Tools
Free online tools for every JSON task — format, validate, convert, compare, and more.