JSON Escape / Unescape
Escape text into a JSON string literal, or unescape a JSON string back to text. Runs locally in your browser.
Escaped output will appear here.What is JSON escaping?
JSON escaping represents arbitrary text as a valid JSON string literal.
What is JSON unescaping?
Unescaping reverses the process: given a JSON string literal, returns the original text.
Common escape sequences
\"- double quote\\- backslash\n- newline\t- tab\uXXXX- Unicode code unit
Why JSON strings need escaping
A JSON string is always wrapped in double quotes, and the parser uses those quotes to know where the string starts and ends. If the text itself contains a literal double quote, a backslash, or a raw control character like a newline, inserting it directly would confuse the parser - it would look like the string ended early, or the JSON would fail to parse at all. Escaping replaces those problem characters with backslash sequences that the parser recognizes as part of the string rather than as syntax.
Quotes, backslashes, and control characters
Three kinds of characters need attention. Double quotes (") must be escaped as \" so they don't prematurely close the string. Backslashes (\) must be escaped as \\, since an unescaped backslash is read as the start of another escape sequence. Control characters - newlines, tabs, carriage returns, and other non-printable bytes - have no literal representation in a JSON string and must use sequences like \n, \t, or a \uXXXX Unicode escape.
A practical example: embedding text inside JSON
Say you want to store the two-line message She said "hi" then pressed enter as a JSON string value. Pasted in raw, the quotes around hi would end the string early, and the line break itself is invalid inside a JSON string. Escaped, the quotes become \" and the line break becomes \n - the result drops in safely anywhere JSON expects a string value, including as a field inside a larger object.
Common escaping mistakes
- Escaping twice - running already-escaped text through Escape again doubles the backslashes, producing a string that unescapes back to the wrong thing.
- Forgetting to escape backslashes in file paths - a Windows path like C:\Users\name needs each backslash doubled, or JSON parsers will interpret \U or \n as escape sequences.
- Pasting a full JSON document into Unescape - Unescape expects a single quoted string literal, not an object or array, and will reject full documents rather than partially process them.
- Manually escaping only quotes and missing control characters - raw newlines or tabs left inside a hand-edited JSON string are invalid even if the quotes are handled correctly.
Escaping vs. encoding or encrypting
Escaping is not the same as encoding or encryption, even though all three transform text. Escaping only makes text safe to place inside a JSON string - it's fully reversible, adds no security, and anyone can read the escaped text with minor mental translation. Encoding, like Base64, repackages bytes into a different alphabet for transport or storage, but is also trivially reversible and not intended for secrecy. Encryption is different in kind: it's designed so the original text can't be recovered without a key. Escaped or encoded text is never a substitute for encryption if the goal is to keep data confidential.
Frequently asked questions
- What's the difference between escaping and unescaping?
- Escaping turns arbitrary text - which might contain quotes, backslashes, or line breaks - into a valid JSON string literal by adding backslash sequences where needed. Unescaping reverses that process, taking a JSON string literal and returning the original, unescaped text.
- Does escaping change my text?
- No. Escaping only changes how the text is represented, not what it says. Round-tripping a string through escape and then unescape returns exactly the original text, character for character.
- Why does Unescape reject a JSON object or array as input?
- Unescape expects a JSON string literal - text wrapped in double quotes, like "hello" - not a full JSON document. An object or array isn't a string literal, so it's rejected rather than guessed at; use a JSON formatter or viewer for full documents instead.
- Is Unicode text preserved correctly?
- Yes - Arabic, CJK characters, emoji, and accented letters all round-trip correctly. They may appear in the escaped output as literal UTF-8 characters or as \uXXXX sequences depending on the character, but either form represents the same text without data loss.
- Why do I need to escape text before putting it inside JSON at all?
- Because JSON strings are delimited by double quotes, any literal quote, backslash, or line break inside the text would break the JSON syntax if inserted as-is. Escaping replaces those characters with safe sequences so the string stays inside its quotes and the surrounding JSON still parses correctly.
Related tools
Format and validate JSON.
Check whether JSON is valid.
Explore JSON as a tree.
Compact JSON.
Compare JSON documents.
Convert JSON to CSV.
Convert CSV to JSON.
Convert JSON to YAML.
Convert YAML to JSON.