Skip to content
TypeParser
All tools

String Escape

Escape strings for JS, Python, Java, JSON.

beats freeformatter.com edge: Per-language target + bidirectional
raw
escaped
target
Guide

About String Escape

Escape special characters (<code>\n</code>, <code>\t</code>, <code>\"</code>, <code>\\</code>) for embedding a string into source code. Pick the target language — JavaScript, Python, Java, C, Go, JSON, SQL, Bash, regex. Each has its own rules; the tool applies the right ones.

When this matters

You have text that needs to live inside a source file as a string literal. Quotes, newlines, backslashes need handling. Each language has its own rules — and getting them wrong means a syntax error or, worse, a silent bug that misinterprets your data.

Language differences

LanguageString quoteNewline escapeNotes
JavaScript', ", ``\nTemplate literals allow real newlines
Python', ", ''', """\nTriple-quoted preserves newlines
Java", """ (text block)\nText blocks added in Java 15
C / C++"\nConcat with adjacent strings
Go", `\nBacktick is raw
JSON"\nStrict — no comments, no trailing comma
SQL'none usuallyDoubled single quote ''
Bash', "variesDifferent rules in single-quoted strings
Regexn/an/aEscape metacharacters

Common workflows

Embed a multiline JSON in a Bash script. Pick Bash target, escape, paste into single-quoted assignment.

Build a regex from a literal string. Pick regex target, escape; the result is the literal pattern.

Move a string between languages. Decode from source A, encode to source B. The tool’s bi-directional escape handles the round-trip.

Fix an embedded SQL injection-prone literal. Use parameterized queries instead — but if you must escape, the SQL target handles doubled quotes correctly.

Frequently asked questions

Which characters get escaped?
The set varies by language. All escape " (or '), \\, newline, tab. Some add control chars, some add unicode. Pick the language for the right rules.
Single-quote or double?
Toggle. Some languages (Python, JS) accept both; the escape changes accordingly. SQL and JSON typically use single and double respectively.
Round-trip?
Yes — toggle Unescape to reverse.
What about regex escape?
Regex has its own metacharacter set (.*+?[](){}|^$\). Pick the regex target to escape those for use as a literal pattern.
HTML / XML?
Use HTML Entities for HTML/XML escaping — different mechanism (entities, not backslashes).
Will it preserve emoji?
Yes. Non-ASCII passes through unchanged unless you toggle the "escape unicode" option, which converts to \u escapes.

Related tools

Last updated: 2025-01-15