JSON Escape/ Escape · Unescape
Escape and unescape JSON strings — handles double quotes, newlines, tabs, and all control characters.
Plain text → JSON string
Plain Text
0 chars
Escaped String
0 chars
JSON Escape Sequences
\\Backslash\"Double quote\nNewline (LF)\rCarriage return (CR)\tTab\fForm feed\bBackspace\uXXXXUnicode code pointDid this tool solve your problem?
Code Examples
JavaScript
const raw = 'Hello "World"\nLine 2';
const escaped = JSON.stringify(raw).slice(1, -1);
// 'Hello \"World\"\\nLine 2'
const unescaped = JSON.parse('"' + escaped + '"');Python
import json
raw = 'Hello "World"\nLine 2'
escaped = json.dumps(raw)[1:-1]
original = json.loads('"' + escaped + '"')Go
raw := "Hello \"World\"\nLine 2" b, _ := json.Marshal(raw) // string(b) includes outer quotes
Shell (curl)
# Escape for curl:
curl -d '{"msg": "Hello\nWorld"}' ...
# Or use Python:
python3 -c "import json,sys; print(json.dumps(sys.stdin.read()))"Frequently Asked Questions
Why does JSON need string escaping?
The JSON spec (RFC 8259) requires special characters in strings to be backslash-escaped. Most commonly: double quotes must be written as \", newlines as \n, and backslashes as \\. Unescaped special characters will cause JSON parsing to fail.
Which characters must be escaped in JSON strings?
Required escapes: double quote ("→\"), backslash (\→\\), and control characters U+0000–U+001F, including newline (\n), carriage return (\r), tab (\t), backspace (\b), and form feed (\f). Other Unicode characters don't need escaping, but can be represented as \uXXXX.
What's the difference between JSON.stringify and manual escaping?
JSON.stringify(str) wraps the result in double quotes and handles all escaping — perfect for producing a complete JSON value. Manual escaping only processes the string's interior without adding quotes, which is what you need when embedding text inside an existing JSON structure.
What is the \uXXXX format?
\uXXXX is JSON's Unicode escape sequence, where XXXX is a 4-digit hex code point. For example, \u0009 is a tab character, \u4e2d is the Chinese character 中. All Unicode characters can be represented this way, but it's typically only used when ASCII-only output is required.
How do I use this when debugging APIs?
Common use cases: 1) Escaping multi-line text before putting it in a JSON field. 2) Preparing JSON body for curl commands — shell quotes conflict with JSON quotes. 3) Embedding SQL queries with single quotes and newlines into a JSON request body.
What's the difference between JSON escaping and HTML escaping?
JSON escaping uses backslashes (\) for string-level special characters to conform to the JSON spec. HTML escaping uses entities (&, <, ") for markup-level characters. In some contexts — like embedding JSON in HTML — both are needed: JSON-escape first, then HTML-escape.