Escape String Online

Convert special characters to their escaped versions for safe use in code

When You Need This

  • Preparing strings for JavaScript/JSON code
  • Inserting text into HTML attributes
  • Building SQL queries safely
  • Creating regex patterns with special characters

How to Use This Tool

  1. Paste your text - Insert any text containing special characters into the input box
  2. Select language - Choose the programming language you need the escaped string for
    • ☑️ JavaScript - Escape strings for JS code and JSON data
    • ☑️ Python - Prepare strings for Python 2/3 code and APIs
    • ☑️ HTML - Encode special characters for HTML/XML documents
    • ☑️ JSON - Strict escaping for JSON data interchange
    • ☑️ Java - Format strings for Java applications
    • ☑️ C# - Escape strings for .NET applications
  3. Set options:
    • ☑️ Escape Unicode: Convert non-ASCII characters (like emojis) to Unicode escapes
    • ☑️ Preserve newlines: Keep line breaks as-is instead of converting to \n
  4. Click "Escape Text" - Your converted string will appear in the output box
  5. Copy the result - Use the output directly in your code

Example Workflow:

1. You paste: Hello "World"! ❤️

2. Select JavaScript format

3. Output becomes: Hello \"World\"! \u2764\uFE0F

What Gets Escaped

  • Quotes ("\")
  • Backslashes (\\\)
  • Control characters (newlines, tabs)
  • Special HTML chars (<<)

Pro Tips

Why escape strings?

Escaping prevents code injection and ensures special characters don't break your syntax.

When should I escape Unicode?

Only when you need ASCII-only output or are working with legacy systems.

What about performance?

Modern browsers handle escaped strings efficiently - no noticeable impact.