Encoders & Converters

String Escape & Unescape Converter

Escape or unescape strings for JSON (RFC 8259), JavaScript/TypeScript, Regular Expressions, SQL literals, CSV fields (RFC 4180), and POSIX shell locally.

Free to use No sign-up Runs in your browser

Tool workspace

What Is a String Escape and Unescape Converter?

Every data format and programming grammar reserves its own delimiter and control characters. Embedding a multiline payload into JSON requires RFC 8259 backslash sequences (\n, \t, \", \\, and \uXXXX for control characters below U+0020), whereas ANSI SQL doubles single quotes ('') and RFC 4180 CSV doubles double quotes (""). This workspace applies strict, grammar-accurate escaping and unescaping for six developer targets—JSON, JavaScript/TypeScript, Regular Expressions, SQL, CSV, and POSIX shells—while reporting exact syntax errors when malformed escape sequences are encountered.

How to Escape or Unescape a String

  1. 1Select Escape to encode a raw multiline string, or Unescape to decode an existing string literal.
  2. 2Choose your target syntax: JSON (RFC 8259), JavaScript, Regular Expression, SQL, CSV, or POSIX Shell.
  3. 3Toggle 'Wrap output in outer quotes' if you need a ready-to-paste string literal with surrounding delimiters.
  4. 4Paste your text into the left editor and copy the transformed result—or click 'Swap & flip mode' to verify round-trip fidelity.

Common Developer Use Cases

Unescaping Nested JSON Strings from API Logs

Decode double-serialized JSON payloads (such as {"payload": "{\"id\":1,\"msg\":\"line1\\nline2\"}"}) back into readable multiline text without manual find-and-replace.

Escaping Literal User Input for Regular Expressions

Convert arbitrary paths, URLs, or currency strings containing metacharacters (., *, +, ?, ^, $, {, }, (, ), |, [, ], \, -) into safe literal regex patterns.

Preparing Multiline SQL, CSV, or Shell Literals

Format strings containing apostrophes like O'Reilly for SQL INSERT statements, RFC 4180 CSV cells, or single-quoted POSIX bash arguments.

Frequently asked questions

Why does JSON.parse fail with 'Bad escaped character' on \' or \x20?

Under RFC 8259 Section 7, JSON only permits eight two-character escapes (\", \\, \/, \b, \f, \n, \r, \t) plus four-digit hexadecimal Unicode escapes (\uXXXX). Escaping a single quote (\'), vertical tab (\v), or two-digit hex (\x20) is valid in JavaScript source code but illegal in strict JSON. Switch the target syntax to JavaScript if you need to unescape those sequences.

How do I escape or unescape a JSON string from the command line?

With jq, run jq -Rs . < input.txt to escape an entire file into a JSON string, or jq -r . <<< '"line1\nline2"' to unescape it. In Python, use python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))'. This browser tool performs the same RFC 8259 transformation locally without shell quoting pitfalls.

Why does POSIX shell escaping use '"'"' instead of a backslash inside single quotes?

In POSIX sh, bash, and zsh, a single-quoted string treats every character literally—even the backslash (\)—until the closing single quote. To include a literal apostrophe safely, the shell closes the single-quoted segment, appends a double-quoted apostrophe ("'"), and immediately reopens single quotes.

Is my string data sent to any external server?

No. All character scanning, Unicode code point conversion, and validation execute locally in your browser.