JavaScript Escape
Escape text for use inside a JS/JSON string literal, live as you type, in either direction.
Escapes text the way it would appear inside a JS/JSON string literal (quotes, backslashes, newlines) โ type in either field, both directions update live. Runs entirely in your browser.
Need the opposite? HTML Escape
What is JavaScript Escape?
Type text and see it escaped the way it would need to appear inside a JavaScript or JSON string literal (quotes, backslashes, and newlines escaped). Type in either field and both directions update live. Handy when hand-building a string literal that contains quotes, backslashes, or line breaks: pasting user-generated text into a JS template, a JSON payload, or a config file without it breaking the surrounding syntax. Everything runs in your browser as you type.
How to Use the JavaScript Escape Tool
- 1
Type or Paste the Text: Enter any text, including quotes, backslashes, or multi-line content.
- 2
Read the Escaped Result Instantly: The JS/JSON-safe escaped string appears automatically as you type.
- 3
Copy the Result: Use the copy button to copy the escaped string for use in code or a config file.
What Gets Escaped and Why
A JavaScript or JSON string literal is wrapped in quotes, so a literal quote character inside the string would end it early unless it's escaped. Backslashes need escaping for the same reason: a backslash starts an escape sequence, so a literal one has to be written as \\ to be read back correctly. Newlines can't appear as a raw line break inside a single-line string literal either, so they're written as \n. This tool produces the same escaping JSON.stringify() would generate, just without the surrounding quotes, so the result drops straight into a string literal you're already writing.
Example
Input:
He said "hi"
Bye
Escaped:
He said \"hi\"\nBye
The quote characters become \", and the line break between "hi" and "Bye" becomes the two-character sequence \n. Both are now safe to drop inside a single-line "..." string literal.Frequently Asked Questions
Common questions about JavaScript Escape.