TTKTheTextKit

String Escape and Unescape Tool

Paste text and escape it so it can sit safely inside a string in JSON, JavaScript, CSV, SQL, a regular expression or a shell command, or paste escaped text and turn it back into plain text. Each language has its own options, such as the quote style, and a count shows how many quotes, backslashes and line breaks were involved. Everything runs in your browser.

Escapes quotes, backslashes, line breaks and control characters, as a JSON string needs.

Escaped
"He said \"it's fine\"\nC:\\temp\\new.txt\tcafé"

Your text has 3 quotes, 2 backslashes, 1 line break, 1 tab and 1 non-ASCII character.

Escaping adds backslashes or doubled quotes so that text containing quotes, backslashes or line breaks stays one string in the code or data format around it. Unescaping reverses it. This tool helps you paste text into JSON, JavaScript, CSV, SQL, regular expressions and shell commands correctly, but it is no defence against injection: build database queries with parameters, not by joining escaped text, and avoid passing untrusted text to a shell. Everything is worked out in your browser and nothing is uploaded.

Related Tools

[5 suggestions]

About the String Escape and Unescape Tool

Escaping makes characters that have a special meaning in a language harmless, so that text containing quotes or backslashes stays one string. JSON strings escape the double quote, the backslash and control characters such as line breaks and tabs, and can write non-ASCII characters as \u sequences. JavaScript strings do the same for the quote that surrounds them, whether single, double or a template literal, where a backtick and ${ also need escaping. A CSV field is wrapped in double quotes when it contains the separator, a quote or a line break, and each quote inside is doubled. Standard SQL doubles single quotes, so O'Brien becomes 'O''Brien', while MySQL string literals use backslash escapes such as \' and \n. For a regular expression, the characters . * + ? ^ $ { } ( ) | [ ] and the backslash get a backslash in front so the text matches literally, and the forward slash can be escaped too for use between slashes. For a POSIX shell, text is wrapped in single quotes and a single quote inside becomes the four characters '\''. Unescaping reverses each rule, removes surrounding quotes if present, and reports where the text is malformed. Escaping is not a defence against injection: database queries should use parameters, and untrusted text should not be passed to a shell.

What does it mean to escape a string?▾

It means adding backslashes or doubled quotes so that characters with a special meaning, such as quotes and backslashes, are treated as plain text. Escaped text can sit inside a string in code without ending it early.

How do I escape quotes in JSON?▾

Put a backslash before each double quote, so say "hi" becomes say \"hi\". Backslashes become \\ and line breaks become \n. The tool does all of this and can write non-ASCII characters as \u sequences.

How do I escape a single quote in SQL?▾

In standard SQL, double it: O'Brien becomes 'O''Brien'. MySQL also accepts a backslash, as in 'O\'Brien'. Where possible, use parameterized queries instead of building SQL from text.

How do I escape text for a regular expression?▾

Put a backslash before every character with a special meaning: . * + ? ^ $ { } ( ) | [ ] and the backslash itself. The result then matches your text exactly, which is useful when searching for user input.

Is my data uploaded?▾

No. The calculation runs in your browser and nothing you enter is sent anywhere.