Skip to content
🛠️ToolsShed

String Escape / Unescape

Escape and unescape strings for JSON, JavaScript, and HTML contexts.

StringEscape.jsonDesc

StringEscape.cheatsheet

\\\
"\"
newline\n
tab\t
carriage return\r
backspace\b
form feed\f

About this tool

String escaping and unescaping is a fundamental task in software development, especially when working with JSON, JavaScript, and HTML contexts. When you include special characters like quotes, backslashes, newlines, or unicode symbols in strings, they must be encoded following format-specific rules to prevent syntax errors or unintended character interpretation. This tool simplifies that process by instantly converting strings between escaped and unescaped forms across multiple formats.

To use the tool, select your target format from the tabs (JSON, JavaScript, or HTML), paste your string into the input field, and choose whether you want to escape or unescape. The tool immediately processes your text and displays the correctly formatted result. You can copy the output with a single click, making it easy to integrate the escaped string directly into your code without manual formatting errors. The tool handles all special characters automatically—quotes, backslashes, newlines, carriage returns, unicode escapes, and more.

This tool is invaluable for developers writing configuration files, API requests, or data exchanges that require proper string encoding. It's also useful when debugging code that handles user input, as you can quickly verify that strings are escaped correctly before processing. Whether you're preparing JSON for a web service, writing JavaScript string literals, or embedding HTML content, this tool eliminates the guesswork and ensures your strings are formatted correctly every time.

Frequently Asked Questions

Code Implementation

import json
import html
import re

text = 'Hello "world"\nLine 2 & <tag>'

# JSON string escaping
json_escaped = json.dumps(text)
print(json_escaped)
# '"Hello \"world\"\nLine 2 & <tag>"'

# Python repr (Python string literal escaping)
py_escaped = repr(text)
print(py_escaped)
# '\'Hello "world"\nLine 2 & <tag>\''

# HTML escaping
html_escaped = html.escape(text)
print(html_escaped)
# 'Hello &quot;world&quot;\nLine 2 &amp; &lt;tag&gt;'

# Regex escaping (escape metacharacters for use in pattern)
regex_escaped = re.escape("price: $4.99 (USD)")
print(regex_escaped)
# 'price:\ \$4\.99\ \(USD\)'

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.