Skip to content
NMSnabbit.

Escape String

Turn raw text into a backslash-escaped string for code.

Encoders & Decoders Runs in your browser

What does escape string mean?

Paste multi-line text and get a single-line, backslash-escaped string that drops straight into JavaScript or JSON. Line one\nline two is literally what a two-line paste becomes; quotes and backslashes are escaped in the same pass. The escaping follows JSON’s rules, so the output is valid inside a double-quoted JSON value with no further editing.

How to use the Escape String

  1. 1 Paste the raw, possibly multi-line string.
  2. 2 The single-line escaped version is generated at once.
  3. 3 Newlines, quotes and backslashes all carry their backslash escape.
  4. 4 Drop the result straight into your JavaScript or JSON.

What you can use it for

  • Pasting text into a code string literal.
  • Preparing values for a JSON payload.
  • Escaping a path or quote for config files.
  • Flattening multi-line text to one line.

Frequently asked questions

How does this differ from HTML encoding?
Different targets: this writes backslash escapes like \n for code strings, while HTML encoding writes entities like & for display in markup. They are not interchangeable.
Why is my multi-line paste now one line?
Each newline became a literal \n, which is the point: a single-line escaped string pastes into a source file without breaking the literal.
Can the output go straight into JSON?
Yes. Quotes, backslashes and control characters are escaped the way RFC 8259 requires, so the result is valid between the double quotes of a JSON string.

Related tools

More Encoders & Decoders

More tools like this:

All Encoders & Decoders