String Escape / Unescape
Escape or unescape strings for JSON, JavaScript, HTML entities, SQL, and regular expressions.
About This Tool
The String Escape / Unescape tool handles five common escaping contexts. JSON / JS String mode escapes characters like ", \, newlines, tabs, and control characters using JSON-standard escape sequences. JS Template Literal mode escapes backticks and$${} interpolation. HTML Entities mode converts&, <, >, ", and' in both directions. SQL mode escapes single quotes by doubling them (ANSI SQL standard). RegExp mode escapes special regex metacharacters for use in a pattern.
How to Use
- Select Escape or Unescape mode.
- Click a language button (JSON, JS, HTML, SQL, or RegExp).
- Paste your input or click Sample to load an example.
- The output updates instantly. Click Copy to copy the result.
Use Cases
Developers escape strings before embedding them in JSON payloads or dynamic SQL queries. Front-end engineers escape HTML content before inserting into innerHTMLto prevent XSS. Regex authors escape literal strings to use them safely as patterns in new RegExp(). Back-end engineers unescape JSON strings from API logs to inspect the raw content. SQL developers escape user input before building parameterized queries or stored procedures.
FAQ
- Should I use this to sanitize SQL inputs in production? β No. Always use parameterized queries or prepared statements in production. String escaping is a manual fallback and is error-prone. This tool is for inspection and learning, not production sanitization.
- What does "unescape" do for RegExp? β RegExp unescape is context-dependent and not well-defined (removing a backslash can change the meaning). This mode returns the input unchanged β manually remove escape sequences for specific cases.
- Does JSON escape handle Unicode characters? β Control characters (U+0000βU+001F) are encoded as
\uXXXX. Printable Unicode characters above U+007F are left as-is (valid JSON allows them). - What is the difference between JSON and JS Template Literal escaping? β JSON strings are delimited by double quotes and escape
". Template literals are delimited by backticks and escape`and${}instead.