Encoders & Text

String Escape / Unescape

Convert between raw text and escaped literals for JSON, JS, C, shell, and SQL.

  • History kept on this deviceRecent results are kept in this browser's local storage until you clear them.
  • Runs in your browserProcessing happens in this page. No application server receives your input.
JSON String

Input

Output

What this tool does

This tool converts raw text into escaped string literals for five target languages (json, js, c, shell, and sql) and unescapes string literals back to raw text entirely in your browser with zero network requests. Every path returns a string and never throws (FR-MISC-12): unparseable or truncated escape sequences fall back to left-to-right sequential replacement.

For example, raw input He said "hi" escapes to JSON He said \"hi\" and to POSIX shell 'He said "hi"'.

Supported flavors

  • JSON (json): Escapes backslashes, double quotes (\"), standard control escapes (\n, \r, \t, \b, \f), and remaining C0 control characters below U+0020 as \uXXXX so the result is always valid inside a JSON string literal.
  • JavaScript / TypeScript (js): Supports double, single, and backtick quote delimiters. In backtick template literal mode, both backticks (\`) and interpolation openers (\${) are escaped so pasted text is never evaluated as a template expression. Line and paragraph separators (U+2028 and U+2029) are also escaped.
  • C / C++ / Go / Java (c): Encodes the string as UTF-8 first and escapes byte by byte. Printable ASCII bytes (0x20..0x7E) are emitted literally (with \", \\, \n, \r, and \t), while non-ASCII and control bytes become \xNN hex byte escapes (so a 4-byte UTF-8 astral character emits four \xNN escapes).
  • POSIX Shell (shell): Wraps the entire argument in single quotes ('...') and replaces each embedded single quote with the close-escape-reopen sequence '\''. Inside POSIX single quotes nothing is special, providing risk reduction against shell metacharacter expansion.
  • SQL (sql): Doubles embedded single quotes ('') without surrounding quotes for reading standard-conforming SQL string literals.

Resilient JSON-flavored unescaping

In Unescape mode, the flavor selector is disabled because unescaping is JSON-flavored for every target. If the trimmed input begins and ends with double quotes and parses as a single valid JSON string literal (such as "a\nb"), the outer quotes are unwrapped automatically (FR-MISC-10). Otherwise, the sequential character scanner resolves \n, \r, \t, \b, \f, \", \\, \/, and \uXXXX in a single pass while preserving leading and trailing whitespace and keeping any unrecognized or truncated escape sequence verbatim.

Security note: SQL and shell boundaries

Escaping a value into SQL text is not how to build a query. Use a parameterized statement; the driver escapes correctly for the server it is connected to. This output is for reading a query, not for running one.

Limits

SQL escaping targets standard-conforming string literals only. Shell escaping targets POSIX sh; it is not correct for cmd.exe or PowerShell. Unescaping is JSON-flavored for every target.

Inputs up to 1.0 MB run synchronously on the main thread, and payloads above 16.0 MB are refused before allocation.

Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.