String Escape and Unescape Tool
Escape and unescape strings for code, regex, CSV, SQL and shell.
Use via API
Escape or unescape a string for JSON, JavaScript, Java/C#, Python, regular expressions, CSV, SQL, POSIX shell or HTML attributes. Send JSON, get JSON back.
POST https://pithlab.com/api/v1/tools/string-escaper
curl https://pithlab.com/api/v1/tools/string-escaper \
-H "Authorization: Bearer $PITHLAB_KEY" \
-H "Content-Type: application/json" \
-d '{"input":"She said \"hi\"\nthen left.","format":"json","quote":true}'About the String Escaper
Escape or unescape text for JSON, JavaScript, Java, C#, Python, regex, CSV, SQL, shell and HTML attributes, with clear errors for malformed escapes.
How to use the String Escaper
- Choose the target format, such as JSON string, Python string or shell.
- Pick Escape to make text safe to paste into that format, or Unescape to turn an escaped string back into plain text.
- Tick Wrap in quotes to add the surrounding quotes, or Escape non-ASCII to turn accents and emoji into \u escapes.
- Copy the result. Malformed escapes are reported with their position.
Examples
Input
Say "hi" then leave
Output
Say \"hi\"\nthen leave
Input
it's here
Output
'it'\''s here'
Input
O'Reilly
Output
O''Reilly
Frequently asked questions
Does SQL escaping protect against SQL injection?
Doubling single quotes makes a value safe inside a standard SQL string literal, but parameterised queries are the right defence in application code. Use this for one off scripts and data fixes.
Why does shell escaping use single quotes?
In POSIX shells nothing is special inside single quotes, so wrapping text in them is the safest quoting. A single quote itself is written as '\'' which closes the quote, adds an escaped quote and reopens it.
What does regex escaping do?
It puts a backslash before characters that have special meaning in a regular expression, such as . * + ? ( ) [ ] and |, so the pattern matches the text literally.
When does a CSV field need quotes?
When it contains a comma, a double quote, a line break, or leading or trailing spaces. The field is then wrapped in double quotes and any double quote inside is doubled.
Why is unescaping rejected?
The input contains an escape the format does not allow, such as \q in JSON, a \u not followed by four hex digits, or an unclosed quote. The error message gives the position.