Escaping is what a document needs before it can live inside a string: a JSON value holding another JSON document, a log line, a shell argument, a fixture pasted into a test file. The rules are short, and this tool applies all of them.
Using the JSON escape and unescape tool
Choose Escape or Unescape, paste your text, and press Convert. Escaping, you can choose whether to wrap the result in quotes and whether to escape everything above ASCII.
Escaping
line1
line2 tab/slash"quote"café
with the default options produces:
"line1\nline2\ttab/slash\"quote\"café"
The newline becomes \n, the tab becomes \t, the quote is escaped, the
forward slash is left completely alone, and café stays as UTF-8 text.
Why the forward slash is left alone
JSON accepts \/ as a valid escape for a literal /, but nothing in the
specification requires it. The habit of escaping slashes comes from
embedding JSON inside an HTML <script> tag, where a literal </script>
sequence would end the tag early. That is a different problem with a
different fix, specific to that one embedding context, and this tool does
not apply it by default. Unescaping still accepts either spelling, since a
document written by something that does escape slashes still needs to read
back correctly.
Escape above ASCII
Turning this on additionally converts every character above the ASCII
range into a \u escape, code point by code point. The é in café
becomes the six characters backslash, u, 0, 0, e, 9, so the
string above ends in caf followed by that escape instead of the letter
itself. This is what you want when the escaped text has to cross something
that is not certainly UTF-8 safe, such as an old system or a transport
that mangles encodings. Leave it off for anything that will be read as
UTF-8, since the escaped form is harder to read for no benefit there.
Fragments are fine
Neither direction requires the input to be valid JSON on its own. Escaping part of a document, a single value you are about to splice into a larger string, is an ordinary thing to want, so the tool works on fragments and separately reports whether the result happens to parse as complete JSON, as a note rather than a verdict.