Multi-Language String Escaper

Turn any text into a safe string literal for the language you are writing, or decode an escaped literal back to plain text, with every language side by side and a round-trip check.

Runs in your browser. Your files never leave your device. See how to check

…

How to do it

  1. 1
    Choose the direction

    Escape text or decode a literal.

  2. 2
    Pick the language

    Choose the target language or context.

  3. 3
    Paste the input

    Paste text or a literal.

  4. 4
    Set options

    Escape non-ASCII characters if needed.

  5. 5
    Check the round trip

    Confirm the result decodes exactly.

  6. 6
    Copy

    Paste the literal into your code.

About this tool

Putting text into source code means escaping it: quotes, backslashes, newlines, tabs and special characters must be written differently in every language. A Windows path, a regular expression, a message with quotes or a snippet with emoji is easy to get subtly wrong, and the mistakes show up as syntax errors or, worse, as text that silently changed. This tool escapes any text into a correct literal for 20 languages and contexts: JSON, JavaScript and TypeScript, Java, C#, C and C++, Go (interpreted and raw), Python (normal and raw), Rust (normal and raw), PHP (single and double quoted), MySQL, PostgreSQL and SQL Server literals, CSS strings, shell single quotes, HTML attributes and regular-expression literal text. It can also decode an escaped literal back to plain text. A round-trip check decodes each result again and confirms you get exactly your input back, and the all-languages table shows every form side by side.

Language notes

- JSON: double quotes, \uXXXX for control characters; U+2028 and U+2029 escaped for safety in JavaScript. - Python raw strings cannot end in a backslash; the tool falls back to a normal string when needed. - Go raw strings cannot contain a backtick; the tool joins parts when needed. - Rust raw strings use as many # marks as necessary so the text cannot end the literal early. - PHP double-quoted strings also escape $ so variables are not interpolated. - PostgreSQL uses doubled quotes in standard strings, and E'…' when backslash escapes are needed. - Shell single quotes cannot contain a single quote, so it is written as '\'' (close, escaped quote, reopen). - CSS escapes use hexadecimal codes followed by a space only when the next character could be read as part of the code.

Non-ASCII characters

By default letters like é and emoji are kept as they are, which all modern source files support in UTF-8. Tick the option to write them as escape codes instead, for files that must stay ASCII.

SQL injection

Escaping literals is fine for scripts and migrations you write by hand. In application code, always use parameterised queries or prepared statements instead of building SQL strings, because escaping rules differ by server settings.

Decoding

Paste a literal including its quotes, choose the language, and switch to decode to see the text it represents, useful for reading escaped strings in logs, JSON or generated code.

Limits

Template literals, f-strings and string interpolation are not evaluated. Character sets other than UTF-8 are not handled. Check generated literals in your compiler or linter; this is a convenience, not a security control.

Worked example

The text He said "it's done" with a newline, a Windows path and an emoji becomes "He said \"it's done\"\nPath: C:\\temp…" in JSON, r'…' is avoided in Python because of the quotes, and every one of the 20 forms passes the round-trip check.

Quick facts

Frequently asked questions

Which languages are covered?

Twenty forms across JSON, JavaScript, Java, C#, C, Go, Python, Rust, PHP, SQL, CSS, shell, HTML and regular expressions.

Can it decode escaped strings?

Yes. Switch the direction to decode.

What is the round-trip check?

The result is decoded again and compared with your input to prove nothing changed.

Should I escape SQL in my application?

No. Use parameterised queries; escaping is for hand-written scripts.

Are emoji and accents kept?

Yes by default; tick the option to write them as codes.

Is my text uploaded?

No. Everything runs in your browser.

Guides for this tool

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages