JSON String Escape and Unescape
Escape quotes, backslashes and line breaks so text can sit inside a JSON string, or unescape an escaped string back to plain text.
Escape quotes, backslashes and line breaks so text can sit inside a JSON string, or unescape an escaped string back to plain text.
Inside a JSON string, characters such as double quotes, backslashes and line breaks must be escaped (\", \\ and \n). Doing it by hand is error-prone, especially for multi-line text or embedded JSON.
This tool escapes plain text for use inside a JSON string and unescapes strings back to readable text.
Input: He said "hi" Output: He said \"hi\"
The JSON standard, RFC 8259, requires that inside a string the double quote, the backslash and all control characters below U+0020 are escaped. Common short forms are backslash n for newline, backslash t for tab and backslash r for carriage return, while other control characters use the backslash u form with four hex digits. Forward slash may be escaped but does not have to be. Anything else, including accented letters and emoji, can appear as it is.
Characters outside the Basic Multilingual Plane, such as many emoji, are written in escaped form as a surrogate pair, two backslash u sequences back to back. Single quotes are not special in JSON, which trips up people used to JavaScript. A frequent mistake is escaping twice: a string that has already been escaped and is escaped again turns every backslash into a double backslash, and the receiver then sees literal backslash characters in the text.
No. You get the contents only, so you can drop it between your own quotes.
The string has an invalid escape such as a lone backslash or an unescaped double quote.
Yes. If the input starts and ends with a double quote, it is parsed as a JSON string.
No. It runs in your browser.
No. Single quotes need no escaping because JSON strings are delimited by double quotes only. A backslash before a single quote is actually invalid in strict JSON.
Emoji sit above U+FFFF, so JSON represents them as a UTF-16 surrogate pair. A compliant parser joins the two codes back into the single emoji when reading.