Convert Newline to \n Online
Instantly convert multiline text into a single-line string with literal \n, \r\n, \\n, or <br> escape sequences—or switch to Unescape Mode to turn \n back into real line breaks. Built for developers formatting JSON payloads, LLM prompts, .env PEM certificates, and multiline string literals directly in the browser.
How to Convert Newlines to \n Online
- Paste Your Text: Enter or paste your multiline text into the Input Text box on the left, or click Load Sample to test with sample paths and quotes.
- Pick a Quick Preset or Mode: Click JSON String, .env / PEM Key, or Code Concatenation for one-click setup, or customize the settings on the right.
- Choose Your Escape Sequence: Select
\nfor Unix/JSON,\r\nfor Windows,\\nfor double-escaped strings, or<br>for HTML—or switch to Unescape Mode to turn\nback into real line breaks. - Copy or Download: The output updates in real time. Click Copy to Clipboard or Download .txt.
Escape Sequence Reference Guide
| Sequence | Name | Where It Is Used | Example Output |
|---|---|---|---|
\n |
Line Feed (LF) | JSON strings, Unix/Linux/macOS, Python, JavaScript, Go, Rust, .env variables |
Line 1\nLine 2 |
\r\n |
Carriage Return + Line Feed (CRLF) | Windows text files, HTTP protocol headers, RFC 4180 CSV files, SMTP email bodies | Line 1\r\nLine 2 |
\\n |
Double-Escaped Backslash | Nested JSON payloads, regular expression literals, shell/sed commands | Line 1\\nLine 2 |
<br> |
HTML Line Break | HTML emails, CMS fields, Markdown cells, rich-text embeds | Line 1<br>Line 2 |
Common Developer Use Cases
1. Formatting Multiline Text & LLM Prompts for JSON APIs
The JSON specification (RFC 8259) forbids raw line breaks inside string values—pasting a multiline prompt or template directly into a JSON body causes a SyntaxError: Bad control character in string literal. Clicking the JSON String preset replaces every line break with \n, escapes internal double quotes (\") and backslashes (\\), and wraps the result in quotes so you can paste it straight into Postman, curl, or an OpenAI/Anthropic API payload.
2. Storing Multiline PEM / SSH Private Keys in .env Files
Docker, Kubernetes, GitHub Actions, Vercel, and Node.js .env files frequently require RSA, TLS, or Firebase private keys (-----BEGIN PRIVATE KEY-----) on a single line. Use the .env / PEM Key preset to strip blank lines, join the base64 blocks with \n, and wrap the key in double quotes:
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQE...\n-----END PRIVATE KEY-----"
3. Building Multiline String Literals in JavaScript, Java, C# & Python
When writing SQL queries, log templates, or shader code in languages where you want explicit line-by-line concatenation, enable Add concatenation operator (or click the Code Concatenation preset) to format each line as "SELECT *\n" + "FROM users\n" + "WHERE active = 1".
Frequently Asked Questions
How do I convert multiline text into a single-line JSON string?
Paste your multiline text into the Input Text box and click the JSON String Quick Preset (or enable Add outer double quotes and Escape inner quotes & backslashes). All line breaks become \n and any internal quotes or backslashes are escaped so the result is valid JSON.
How do I convert literal \n back into actual line breaks (unescape)?
Select Unescape (\n → Newline) under Conversion Mode in the settings panel, or click the Unescape \n → Lines preset. Paste your escaped string and it will immediately expand into readable multiline text.
How do I format a multiline PEM or SSH private key for a .env file?
Paste the full key (including -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----) and click the .env / PEM Key preset. It trims stray spaces, removes blank lines, replaces newlines with \n, and wraps the key in double quotes.
What is the difference between \n (LF) and \r\n (CRLF)?
\n (Line Feed, ASCII 10) is the standard newline sequence in Unix, Linux, macOS, JSON, and most modern programming languages. \r\n (Carriage Return + Line Feed) is used by Windows text files, HTTP protocol headers, and RFC 4180 CSV files.
Is my text or private key uploaded to any server?
No. Every conversion runs 100% locally in your web browser using JavaScript. Your text, API payloads, and private keys never leave your device.