JSON Escape / Unescape: Safe String Handling
Embedding raw strings inside JSON requires escaping characters that would break JSON syntax — double quotes, backslashes, and control characters like newlines and tabs. This tool escapes raw text into a valid JSON string literal or unescapes a JSON string back to its original form.
Frequently Asked Questions
What characters does JSON escaping handle?
JSON escaping replaces: double quotes (" → \"), backslashes (\ → \\), newlines (\n), carriage returns (\r), tabs (\t), and control characters (\u0000–\u001F).
What is the difference between escape and unescape?
Escape converts a raw string into a JSON string literal (adds surrounding double quotes and escapes special chars). Unescape does the reverse — parses a JSON string literal back to the raw string.
When do I need to escape a string for JSON?
When you are building a JSON payload by hand and your string value contains quotes, newlines, or backslashes. For example embedding SQL or code strings inside JSON.
Why does the escaped output include outer quotes?
A JSON string is always surrounded by double quotes. The escaped output is a valid JSON string value — paste it directly into a JSON document.
What if unescape fails?
Unescape uses JSON.parse() internally. If the input is not a valid JSON string (e.g. missing surrounding quotes or invalid escape sequence), you will see a parse error.
Can I escape multi-line text?
Yes. Newlines become \n and tabs become \t in the escaped output. This lets you embed multi-line strings safely inside a single JSON field.