Newlines to escape sequences
Flatten multi-line text into one line: line breaks become \n or \r\n literals (LF / CRLF / CR), or JS strings, JSON strings and %0A URL encoding. Mixed CRLF, CR and LF input is normalised, the trailing newline can be kept or dropped, and the result never contains a real line break.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Line breaks become literals inside a single line. \r\n, \r and \n each count as one break, and a single trailing newline is dropped by default.
Single-line result
One line with no real line breaks, ready to paste into a shell command, code or JSON value.
Enter multi-line text to see the escaped result
Lines: 0 · Line breaks: 0 · Blank lines: 0 · Input chars: 0 · Output chars: 0
What this tool does
- Collapse multi-line text into a single line: newlines become \n literals that survive command lines, environment variables and config files.
- Emit JSON or JS strings: the matching format escapes backslashes, quotes and control characters so the value can be pasted into code safely.
- Build URL parameters from multi-line input using %0A / %0D%0A instead of real newlines that can truncate a request.
Example
Input
第一行 第二行
Output
第一行\n第二行
By default the output uses \n literals with LF line breaks and drops a single trailing newline. LF, CRLF and CR input are all normalised to the chosen type.
Frequently asked questions
Where did the trailing newline go?
Text copied from an editor almost always carries one extra newline, so a single trailing newline is dropped by default. Enable "Keep trailing newline" to preserve it — the newline count in the stats grows by one as well.
What about CRLF (Windows) input?
No conversion step is needed: \r\n, \r and \n each count as one line break and the output flavour is decided by the "Line break type" option (LF → \n, CRLF → \r\n, CR → \r). Mixed files from different systems are handled in one pass.
What do the js and json modes escape?
The js mode escapes backslashes, single quotes and double quotes. The json mode escapes backslashes and double quotes and rewrites tabs, \b and \f as short escapes, with the remaining C0 control characters as \u00XX. The escape and percent modes only replace line breaks and leave the content untouched.
Does the output still contain real newlines?
No. The result is always a single line with no real line breaks, so it can be pasted into a one-line input, a shell command or a JSON field. For the opposite direction (turning \n literals back into real newlines) use the "escape sequence to line break" tool.
Keywords:newlines to escapes