String Escaper

Escape or unescape text for JSON, JavaScript, regex, SQL, CSV and more.

Direction
0 words · 0 charactersNot uploaded

Escape text for code and data formats

Every format has characters that need escaping. Get them wrong and you get syntax errors, or injection bugs.

Format What changes
JSON " and \ escaped; newlines, tabs and control characters as \n, \t, \u0000
JavaScript as JSON, plus single quotes and the line/paragraph separators U+2028/2029
C / Java quotes, backslashes, \n \r \t, other control characters as \xNN
Regular expression `. * + ? ^ $ { } ( )
SQL single quotes doubled (O'Brien → O''Brien)
CSV fields with commas, quotes or line breaks wrapped in quotes, inner quotes doubled
XML / HTML attribute & < > " ' as entities
Shell wrapped in single quotes, inner single quotes handled with '\''

Unescape reverses each format: \n becomes a real newline, \u00e9 and \u{1F600} become characters, \x41 becomes “A”.

A word on SQL

Escaping quotes is not a defence against SQL injection in application code, use parameterised queries. The SQL mode is for writing literals by hand, such as in a migration or a one-off query.

Worked example

Here is what the String Escaper returns for its built-in example. Settings used: Direction: Escape; Format: JSON string. Click Try an example in the tool above to load it, then change it as you like.

Input
She said "hello"
and left at 5 o'clock — price: $10.00 (approx.)
Output
She said \"hello\"\nand left at 5 o'clock — price: $10.00 (approx.)

Related tools: Regex Tester, HTML Entity Encoder/Decoder.

Questions

How do I escape quotes in JSON?

Choose JSON and Escape. Double quotes become " and backslashes become \, along with newlines and control characters.

How do I unescape \n into new lines?

Choose Unescape with JSON or JavaScript; \n, \t and \uXXXX sequences become real characters.

Last reviewed · How Textkiln tools work