How to use this tool
- Paste text into the input and select the context (JSON, JavaScript, regex, or newline/tab).
- Choose Escape or Unescape to perform the conversion.
- Copy the result, clear inputs, or swap input and output for another pass.
About Text Escape Unescape
This tool helps you prepare strings for embedding in JSON, JavaScript, or regex literals, or to make newlines and tabs visible. Each context uses different escape rules, so choose the one that matches your target.
Common use cases
- Escaping user input before embedding in JSON or JavaScript string literals
- Preparing a literal string for use inside a regex pattern
- Converting newlines and tabs to visible escape sequences for debugging
FAQ
- What does this tool do?
- It escapes or unescapes text for specific contexts: JSON strings, JavaScript strings, regex literal patterns, and newline/tab visibility. Each context has different rules, so the output depends on the mode you select.
- Does this tool sanitize or validate input for security?
- No. It only applies escape/unescape rules. Escaping for JSON or regex does not sanitize against XSS or other injection. Use proper validation and encoding for security-sensitive contexts.
- Why does JSON escaping differ from regex escaping?
- JSON escapes quotes, newlines, and control characters for string literals. Regex escaping backslash-prefixes special metacharacters so they match literally. The rules are different because the contexts differ.
- What if unescape fails with an error?
- Check that the input uses valid escape sequences for the selected context. Invalid sequences like malformed \uXXXX or stray backslashes will cause an error. Ensure you chose the correct mode for your input.