String Escape / Unescape
Escape or unescape strings for JSON, JavaScript, SQL, and Regex in your browser. Toggle between encode and decode modes. No data leaves your device.
Input
Escaped
Related Tools
Unix Timestamp
Convert Unix timestamps to UTC, local time, and ISO 8601 instantly. Auto-detects seconds vs milliseconds.
Base Converter
Convert numbers between decimal, hex, binary, and octal instantly. Free and runs in your browser.
Hash Generator
Generate SHA-1, SHA-256, SHA-384, and SHA-512 hashes instantly. Runs entirely in your browser using the Web Crypto API.
String escaping is the process of replacing special characters in a string with escape sequences that the target language or format can safely parse. Different contexts define different sets of special characters. In JSON strings, double quotes and backslashes must be escaped because they are structural characters. In SQL, single quotes must be doubled or escaped because they delimit string literals. In JavaScript regex patterns, metacharacters like ., *, +, ?, ^, $, {, }, [, ], (, ), |, and \ must be escaped to match them literally.
The inverse operation — unescaping — restores the original string from its escaped form. This is equally necessary: when reading escaped strings in log files, debugging JSON payloads, inspecting database query strings, or extracting regex patterns from configuration files, seeing the raw unescaped string is often more readable than the escape-sequence form. Unescaping allows developers to verify what a string actually contains without mentally translating each escape sequence.
This tool handles escaping and unescaping in four modes: JSON (double quote, backslash, and control character escaping per RFC 8259), JavaScript (same as JSON plus single quote and backtick for template literals), SQL (single-quote doubling for ANSI SQL string literals), and Regex (metacharacter escaping to produce a literal pattern string). Both directions are available via a toggle. The conversion runs in the browser on every keystroke with no server round-trips.
Common Use Cases
Embedding multiline strings in JSON configuration files
JSON configuration files (package.json scripts, GitHub Actions workflow inputs, AWS Lambda environment variables, Terraform locals) require strings to be on a single line with newlines expressed as \n and backslashes doubled. When copying a SQL query, regex pattern, or shell command into a JSON value, JSON escaping replaces literal newlines and backslashes with their escape sequences, producing a valid JSON string value.
Building regex patterns from literal search terms
When constructing a regex programmatically from user input or configuration values, the input string must be regex-escaped to treat it as a literal match rather than a pattern. A search term like '2.5' would match '205' without escaping because . is a regex wildcard. Escaping the string to '2\.5' ensures the regex matches only the literal decimal number. This is the standard technique used in search-and-replace features, input validation, and dynamic pattern construction.
Preparing strings for SQL query logging and debugging
When logging dynamic SQL queries for debugging or audit purposes, string values must be SQL-escaped before interpolation into the log message to produce a valid, re-runnable SQL statement. The SQL escape mode doubles single quotes inside string values, matching the escaping that a parameterized query driver applies internally. This lets developers copy the logged query directly into a database client to reproduce a query from production logs.
How to Use
- Paste your string into the input panel.
- Select the escape mode: JSON, JavaScript, SQL, or Regex.
- Toggle the direction between Escape (raw → escaped) and Unescape (escaped → raw).
- The result appears instantly in the output panel.
- Click Copy Output to use the result in your project.
Escape Mode Reference
- JSON — Escapes
"→\", backslash →\\, newlines →\n, tabs →\t. Used when embedding strings in JSON values. - JavaScript — Same as JSON but also escapes single quotes and template literal backticks. Used for JS string literals.
- SQL — Escapes single quotes as
''(doubled). Used to safely embed values in SQL queries. - Regex — Escapes metacharacters:
. * + ? ^ $ | ( ) [ ] { } \. Used to treat a string as a literal pattern.
Common Use Cases
- Embedding user-generated text inside JSON API payloads
- Building dynamic SQL queries safely (always prefer parameterized queries)
- Constructing regex patterns from literal strings
- Debugging escaped strings by unescaping them for readability