About the JSON Multiline String
The JSON grammar forbids a raw line break inside a string. An email body, a certificate, a shell script or an SQL statement therefore has to be folded before it can sit in a configuration file or a request body. This converter escapes every newline as \n, escapes the quotes and backslashes around it, and hands back a literal that any parser will accept.
Four shapes cover the common house styles. One string keeps the text in a single value. An array of lines is easier to review in a pull request because each line diffs on its own. An object with a named key produces a ready made field such as {"body": "..."}. Concatenated pieces prints one quoted fragment per line for languages where the source is easier to read that way.
The line ending selector matters more than it looks. A Windows program that writes CRLF produces \r\n pairs, and a checksum or a test comparison against LF text will fail on that invisible difference. Trimming each line removes the trailing spaces that survive a copy from a terminal.
Switch the direction to unfold a stored value back into readable lines before editing it. For escaping other characters rather than newlines, see JSON Escape, and for whole documents rather than plain text see JSON to String.
How to use
- Paste the multi-line text on the left, or press Sample to load a short letter.
- Choose a shape: one string, an array of lines, an object with a key, or concatenated pieces.
- Set the line ending to CRLF if the text must keep Windows endings.
- Switch Direction to unfold an existing JSON string back into plain lines.
Common questions
- Why can I not just press Enter inside a JSON string?
- The specification treats a raw line break as a control character and rejects it. The break has to be written as the two character escape \n instead.
- Which shape is best for a long block of text?
- An array of lines, because a code review then shows exactly which line changed instead of one enormous modified string.
- Does unfolding accept an array as well as a string?
- Yes. An array of strings is joined back with the selected line ending, and an object is unfolded from its first string or array value.
- What happens to tabs in my text?
- They are escaped as \t, so indentation inside the block survives the round trip untouched.