FormatterHQ

JSON Multiline String Converter

Paste multi-line text such as SQL, an email template or a PEM key and get a valid JSON string, a JSON array of lines, or concatenated string literals for code.

Input TEXT
Output JSON
Ready.

How to use the JSON Multiline String Converter

  1. Paste the multi-line text, or click Sample to load a short message.
  2. Choose the Output: a single JSON string, a JSON array of lines, or concatenated string literals.
  3. For the array output, pick an Indent.
  4. Click Convert and copy the result into your JSON file or code.

JSON multiline string: why a converter helps

JSON has no multiline string syntax. A string value must sit on one line, and every line break inside it has to be written as \n. This JSON multiline string converter takes ordinary text with real line breaks and produces a value you can paste into a JSON document without a parse error.

Example: a SQL query for a config file

SELECT id, "name"
FROM users
	WHERE active = 1

The input has three lines, a pair of double quotes and a tab at the start of the last line.

The three output modes

Single JSON string (\n escapes)

"SELECT id, \"name\"\nFROM users\n\tWHERE active = 1"

The default. Quotes are escaped, the tab becomes \t and the line breaks become \n. The status bar confirms "3 lines joined into one JSON string". Use it for any JSON property that holds text.

JSON array of lines

[
  "SELECT id, \"name\"",
  "FROM users",
  "\tWHERE active = 1"
]

Each line becomes one array element, printed with the Indent you choose. This is easier to read and review in a diff, and some formats expect it, for example the body of a VS Code snippet. The program reading it must join the lines itself.

Concatenated string literals

"SELECT id, \"name\"\n" +
"FROM users\n" +
"\tWHERE active = 1"

One literal per line, joined with +, with the line break kept at the end of each piece. This form is meant for source code in languages such as JavaScript, Java or C#, where it keeps a long text readable.

Line endings and edge cases

  • Windows line endings (CRLF) and old Mac ones (CR) are normalized to \n, so the result is the same whichever system the text came from.
  • A trailing newline counts as a line: text ending in a line break gives a string ending in \n, and an empty last element in the array mode. Delete the final newline if you do not want it.
  • Leading spaces and tabs are kept exactly; nothing is trimmed.

Typical uses

Queries and templates stored in JSON config, prompt text in JSON datasets, and certificates or private keys in PEM format all need this treatment. For example, cloud service-account key files store the PEM key as one string full of \n escapes. For going the other way, from an escaped string back to readable text, use JSON unescape. To embed a whole JSON document rather than plain text, use JSON to String.

The text is converted in your browser and is not uploaded.

Frequently asked questions

Can a JSON string span multiple lines?
No. JSON strings cannot contain raw line breaks; they must be written as \n escapes. Store the text as one escaped string, or as an array of lines that your program joins.
How do I store a PEM key or certificate in JSON?
Paste the whole key, including the BEGIN and END lines, and use the Single JSON string output. Every line break becomes \n, which libraries decode back into the original key.
Why is there an empty string at the end of my array?
The input ended with a line break, so the text after it counts as an empty last line. Remove the final newline before converting if you do not want that element.
Are tabs and quotes escaped?
Yes. Double quotes become \", tabs become \t and backslashes are doubled, following the normal JSON string rules.

Last updated October 3, 2026

Related tools

CSV to Multi-line Data Converter Convert CSV to Multi-line Text online for free. Every value on its own line, record by record. Multiline to Single Line Join multiple lines into one line with a space, comma or custom separator, optionally quoting each item. JSON to Query String Build URL-encoded query strings from JSON objects, with a choice of bracket, indexed or repeated keys for arrays. JSON to String Converter Convert JSON to a single escaped string you can paste into code, databases or other JSON documents. Choose double, single or no quotes. Query String to JSON Parse URL query strings into JSON, including repeated keys, PHP/Rails bracket arrays (a[]=1) and nested objects (a[b][c]=1). String to JSON Converter Convert an escaped JSON string back into formatted JSON. Handles quoted literals, backslash-escaped text and double-encoded JSON. JSON Navigator Navigate JSON by path. Browse or filter the tree and click any key to see and copy the full path to that value. JSON Parser Parse JSON online: errors with line and column, the parsed values with their types, and the pitfalls of big integers and duplicate keys. JSON Patch Tester (RFC 6902) Apply RFC 6902 JSON Patch operations (add, remove, replace, move, copy, test) to a document and see exactly which step fails. JSON Patch Generator (Diff to Patch) Compare two JSON documents and generate the RFC 6902 JSON Patch that transforms the first into the second, with optional test ops. JSON Path Finder Click any value in a JSON tree to get its path as JSONPath, JavaScript, Python, PHP, jq or JSON Pointer — or list every path. JSON Pretty Print Pretty print JSON online with a 4-space default, 2 or 3 spaces or tabs, and see the matching JavaScript, Python, PHP and jq commands.