String Escape

Convert a text into an escaped string (\n, \", \\) ready to embed in code, and back.

What string escaping is

When embedding text inside source code (like a JSON string or a JavaScript variable), special characters such as line breaks, quotes and backslash need to be "escaped" — represented as a sequence like \n (line break), \" (quote) or \\ (backslash) — so the text is parsed correctly.

When to use it

Useful when building a JSON payload by hand, embedding multi-line text on a single code line, or debugging a string that came with escape characters and you want to read the original text.

A worked example

The two-line text He said "hi" and C:\temp turns into a single line with \n between the parts, \"hi\" for the quotes and C:\\temp for the path. Windows paths are the classic source of confusion: every backslash has to be doubled.

Pitfalls when reversing

To undo an escape, paste the whole string including the outer quotes; a lone trailing backslash or an invalid sequence such as \q makes JSON parsing fail. Single quotes need no escaping in JSON, and emoji or accented letters either stay readable or appear as \uXXXX codes, depending on the input.

Frequently asked questions

Does the escaped result include the outer quotes?

Yes — the result is a valid JSON string, including the double quotes at the start and end, ready to paste into code.

Does this work the same for JSON and JavaScript?

Yes, the escaping rules used here (based on JSON) are compatible with JavaScript strings.

What happens to tabs and control characters?

A tab becomes \t and a carriage return becomes \r. Other invisible control characters are turned into \uXXXX codes, which helps explain why a seemingly normal string breaks a parser. Plain letters and digits are never changed.

Can I escape a string for use inside a regex or SQL?

No. This follows JSON rules only. Regular expressions need their own escaping of characters like the dot and parentheses, and SQL values should be passed as bound parameters rather than escaped by hand.