\x prefix), Escape for string literal (JSON.stringify), or Unescape string (JSON.parse).Backslash escaping is the difference between a string that compiles and a syntax error. JSON requires " inside values to become \"; JavaScript and Python string literals need \n, \t, \r for control characters; Windows paths must double every \ when they live inside a string. This tool handles each of those cases without forcing you to escape the wrong things — pick exactly the character classes you want, or hand the whole string to JSON.stringify in one click.
Add and Remove modes run direct character-class regex passes — backslashes are processed first so they aren't double-escaped on a second pass. Escape for string literal hands the input to JSON.stringify and slices off the wrapping quotes, so the output is a fully valid JS or JSON string body. Unescape goes through JSON.parse, so \uXXXX sequences and \n/\t/\r/\"/\\ are all decoded; if parse fails on malformed input, a fallback regex pass handles the common short forms.
\uXXXX escapes via JSON.parse — no octal support (JSON forbids it)Add backslashes lets you tick exactly which character classes get prefixed (quotes, newlines, tabs, backslashes). Escape for string literal runs JSON.stringify and returns the inner contents — a fully valid JS or JSON string body, including any required \uXXXX sequences.
Backslash is the escape character, so C:\Users is parsed as C: followed by an escape of U. Each backslash must be doubled to C:\\Users\\name, which the Add backslashes mode produces in one click when the Backslashes box is ticked.
Unescape goes through JSON.parse, so \n, \t, \r, \", \\ and \uXXXX sequences are all decoded. Legacy octal escapes like \012 are not — JSON forbids them — and a fallback regex pass handles the most common short forms instead.
In Add mode with the Backslashes option ticked, every literal backslash is doubled, so an existing \n becomes \\n. Untick Backslashes to leave existing escape sequences alone and only escape quotes, newlines or tabs.
See also JSON Formatter, Regex Tester, and URL Encoder for related escaping needs.