Backslash Escape Converter
Escape and unescape backslash sequences in strings.
Escaped
Escaping strings for code
When you embed text inside a string literal, certain characters need a backslash escape: a literal backslash becomes \\, a double quote becomes \", a newline becomes \n, and a tab becomes \t. Escape mode prepares text for pasting into JSON, JavaScript, or a config file; unescape mode turns those sequences back into the real characters. Conversion uses JSON's own rules and runs entirely in your browser.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Preparing a string containing quotes and newlines for a source-code literal.
- Reading an escaped string out of a log back into what it actually contains.
- Escaping a Windows path for a language that treats backslash as an escape character.
- Checking whether a value is double-escaped somewhere in a pipeline.
- Producing a JSON string value from raw text with the right escapes.
Frequently Asked Questions
- Which escapes are standard?
- \n newline, \t tab, \r carriage return, \\ backslash, \" and \' quotes, \0 null, plus \xNN and \uNNNN for hex and Unicode. Beyond these, languages differ — \e for escape works in some and not others.
- Why does Windows path handling go wrong?
- Because C:\new\table contains \n and \t, which become a newline and a tab rather than literal characters. Either double every backslash or use a raw string — this is the classic Windows path bug.
- What is a raw string?
- One where escapes are not processed: r"..." in Python, backticks in Go, @"..." in C#. They are the right tool for regex patterns and paths, where backslashes are data rather than instructions.
- How many backslashes does a regex need?
- Often four to match one literal backslash, because the string literal consumes a level before the regex engine sees it. That double-escaping is why regexes in string form become unreadable so quickly.
- Does JSON support the same escapes?
- A smaller set — no \x, no single-quote escape, and no octal. Non-ASCII must use \uNNNN. Pasting a JavaScript string literal into JSON therefore often produces invalid JSON.
- Why does a regex in a string need doubled backslashes?
- Because two layers consume them — the string literal parses `\\d` into `\d`, and the regex engine then reads that as the digit class. Writing `\d` in a normal string yields just `d`, which silently matches the wrong thing.
- How do shell quoting rules differ?
- Single quotes in POSIX shells make everything literal including backslashes; double quotes still process them. PowerShell uses a backtick rather than a backslash entirely, which is why a command copied between the two breaks.
Common errors and gotchas
- Double escaping, where a single backslash becomes two and the consumer sees a literal backslash.
- Assuming the escape set is universal, when JSON, C and shell all differ on what needs escaping.
- Escaping a Windows path once when the target needs it twice, or the reverse.
- Overlooking that a lone backslash at the end of a string escapes the closing quote.
- Treating a Unicode escape as a backslash escape, which needs a different transformation.
Related Encoders & Decoders tools
Base64 Encoder
Encode or decode Base64 strings.
URL Encoder
Safely encode or decode URL parameters.
Base Converter
Convert numbers between binary, octal, decimal, hex, and base 2-36.
ROT13 Encoder / Decoder
Apply the reversible ROT13 letter-substitution cipher.
HTML Entity Encoder / Decoder
Escape or unescape HTML entities like & and <.
Punycode Converter
Convert internationalized domains to and from Punycode.
Text to Morse Code
Translate text into Morse code dots and dashes.
Morse Code to Text
Decode Morse code dots and dashes back into text.