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.