Skip to content
Buy me a coffee
String Escaper & Utilities

JSON Escape / Unescape

Escapes or unescapes a JSON string, replacing characters that could prevent parsing with their escape sequences.

Ctrl + Enter

JSON string escaping explained

Why escape?

Every string in a JSON document is delimited by double quotes, and RFC 8259 forbids unescaped double quotes, backslashes and control characters (U+0000 through U+001F) inside it. A strict parser rejects the whole document when it meets a raw line break in a string, so multi-line text, Windows paths and quoted phrases must be escaped before being placed in a JSON value. This tool escapes the content of a string: paste the result between double quotes.

Rules applied by this tool

CharacterEscaped asNotes
Backspace (U+0008)\b
Form feed (U+000C)\f
Newline (U+000A)\n
Carriage return (U+000D)\r
Tab (U+0009)\t
Double quote\"
Backslash\\Handled first.
Other control characters (U+0000–U+001F)\u0000\u001fJSON has no \v, \0 or \xXX forms: only \uXXXX is allowed.
Forward slash\/Optional. Allowed by the specification and used by some encoders (PHP's json_encode by default) so that </script> cannot appear literally inside an HTML page.
Non-ASCII characters (é, 日, 😀)\u00e9, \u65e5, \ud83d\ude00Optional. Produces pure ASCII output that survives any transport encoding; characters above U+FFFF are written as a UTF-16 surrogate pair.

Single quotes are never escaped: they have no special meaning in JSON, and \' is actually invalid JSON.

Before / after

InputEscaped output
He said "hi"He said \"hi\"
C:\temp\file.txtC:\\temp\\file.txt
Two lines separated by a line breakline one\nline two
https://example.com/a (with the slash option)https:\/\/example.com\/a
Café (with the \uXXXX option)Caf\u00e9

Unescaping

The unescape button decodes the seven two-character escapes, \/ and \uXXXX. Sequences that are not valid JSON escapes (for example \x41 or \') are left untouched so you can spot them. When you have a complete JSON document rather than a single string, use the JSON formatter or JSON validator instead.

In code

// JavaScript: JSON.stringify escapes and adds the surrounding quotes
JSON.stringify('He said "hi"\n');          // "He said \"hi\"\n"

// PHP
json_encode($s, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

// Python
json.dumps(s, ensure_ascii=False)

// Java (Jackson)
new ObjectMapper().writeValueAsString(s);