JSON Multiline String Converter

Paste a config block, a certificate, or a SQL query. Get one JSON value with every line break escaped, or turn an escaped string back into lines.

Convert

0 lines

Paste text or press Load sample.

  • \n0
  • \r0
  • \t0
  • \"0
  • \\0
  • \u0
0 characters

JSON has no multi-line string syntax

Python has triple quotes. YAML has | block scalars. JavaScript has backticks. JSON has none of these. The spec (RFC 8259, section 7) forbids raw control characters between quotes, so a pasted paragraph breaks the parser on its first line break.

Rejected by every JSON parser
{
  "footer": "Toolexe
Free developer tools"
}
Valid, same text
{
  "footer": "Toolexe\nFree developer tools"
}

The converter above writes the second form for you. Paste the text with real line breaks, pick a shape, copy the result into your file.

What each character turns into

JSON.stringify follows these rules. The tally strip in the converter counts each row for your text, so you see at a glance whether a Windows file slipped \r characters into the value.

In your textIn the JSON stringNote
Line break (LF)\nThe main reason this page exists.
Carriage return (CR)\rComes from files saved on Windows. Usually unwanted.
Tab\tIndentation survives the round trip exactly.
Double quote\"Single quotes stay as they are.
Backslash\\Windows paths double in length: C:\\logs.
Other control characters\u0000 to \u001fRare in text, common in pasted terminal output.
U+2028, U+2029\u2028, \u2029Valid raw in JSON, fatal in older JavaScript. Always escaped here.
Accents, emojiUnchangedTick ASCII only to write \u00e9 style escapes instead.

Three shapes for long text, ranked

1. Escaped string

One value, one line. Programs read the text back with no extra step. A certificate in "tlsCert", an email template, a migration query. Hard to edit by hand once the text grows past a few lines.

Best default for machine-written files.

2. Array of lines

Each line becomes one array item. A reviewer sees a one-line change as one changed row in git. The reading code joins the items with "\n", a step people forget.

Best for config files people edit, such as VS Code snippets.

3. Base64

Encode the bytes, store one opaque string. Safe for binary data plus text with mixed encodings. Unreadable in review, 33 percent larger.

Only for binary content. Not offered here on purpose.

Worked example: a PEM certificate in a deploy config

A deploy file for staging.toolexe.com needs the TLS certificate inline. The certificate runs 30 lines, Base64 rows between two marker lines.

  1. Open the .pem file, copy everything from -----BEGIN CERTIFICATE----- to the end marker.
  2. Paste into the box above with Text to JSON selected.
  3. Pick Key-value pair, type tlsCert as the key, keep Line endings on LF.
  4. Check the tally. Expect 29 or 30 under \n plus zero under \r. LF mode drops Windows carriage returns before escaping.
  5. Copy the line into the config object, then validate the whole file in the JSON Beautifier.

Going the other way, paste "tlsCert": "-----BEGIN..." with JSON to text selected. The converter strips the key, decodes the escapes, plus shows the original 30 lines ready to save as a file.

Where conversions go wrong

Escaping twice

Paste an already escaped string into Text to JSON plus every \n becomes \\n. The receiving program then prints a literal backslash-n instead of a line break. If the tally shows a high \\ count on text without Windows paths, switch direction.

CRLF sneaking into values

Text copied from Notepad or a Windows checkout carries \r\n. Most Unix tools show the stray \r as ^M or break shell scripts with bad interpreter. LF is the default here for this reason. Choose Keep only when you need a byte-exact copy.

Trailing whitespace

Markdown treats two trailing spaces as a hard line break. Trim trailing spaces removes them, so leave the box empty for Markdown content.

When this is the wrong tool

If people hand-edit the file every week, a 40-line escaped string becomes a source of mistakes. Move the text to its own file plus store a path in JSON, or switch the config to YAML where a | block keeps line breaks readable. The JSON to YAML converter handles the move.

To embed a whole JSON object as a string, use JSON Stringify. The page parses the object first, which catches syntax errors this converter treats as plain text.

Everything runs in your browser. Inputs of a few megabytes convert without delay on a laptop. Past about 20 MB the textarea itself slows down before the conversion does.

Multi-line JSON questions

Line breaks, CRLF, arrays versus strings.

Does JSON support multi-line strings?

No. RFC 8259 forbids raw control characters inside a string, line breaks included. Every line break has to appear as the two characters \n, or the text has to be split into an array of lines.

Why does my parser fail on a pasted block of text?

A literal line break inside quotes ends the string early from the parser view. The error usually names the first line after the break. Run the text through Text to JSON here, then paste the escaped result.

Should I pick a string or an array of lines?

Pick a string when code reads the value as one block, such as a certificate, a template, or a SQL query. Pick an array when people edit the JSON by hand or review diffs, since each line becomes one row in version control.

Why do I see \r\n in the output?

The source used Windows line endings. Set Line endings to LF before converting unless the consuming program expects CRLF, as some SMTP or CSV readers do.

Is my text sent to a server?

No. Escaping, decoding, the tally, copy, plus download all run in this browser tab.