JSON Escape and Unescape
Escape quotes, backslashes and line breaks so any text fits inside a JSON string, or unescape \n, \" and \u codes back into readable text. Results appear as you type.
" → \" · \ → \\ · new line → \n
Hi \"Sam\",\nYour report is saved in C:\\Reports\\2026.\n\tThanks!
7 characters escaped. Paste it between the quotes of a JSON value: "message": "…"
Everything runs in your browser; nothing is uploaded.
What is JSON escaping?
A JSON string starts and ends with a double quote, so a quote inside the text would end it early. Escaping puts a backslash in front of the characters that would break the string, and writes line breaks and tabs as \n and \t, because a JSON string must stay on one line.
{"note": "She said "hi""} ✗ invalid: the string ends at "She said "
{"note": "She said \"hi\""} ✓ reads as: She said "hi"Unescaping is the reverse. It turns \", \n and \u00e9 back into ", a real line break and é, so you can read a message copied out of a log, an API response or a database.
JSON escape characters
JSON has only a handful of escapes. Some are required, some optional, and a few that look familiar aren’t allowed at all:
| Character | Escape | Needed? |
|---|---|---|
| " double quote | \" | Required |
| \ backslash | \\ | Required |
| Line break, carriage return, tab | \n \r \t | Required |
| Backspace, form feed | \b \f | Required |
| Other control characters | \u0000–\u001f | Required |
| / forward slash | \/ | Optional |
| Any other character (é, 日, 😀) | \u00e9 | Optional |
| ' apostrophe | \' | Not allowed |
| Hex or octal codes | \x41 \101 | Not allowed |
Emoji and other characters beyond \uffff are written as two codes, for example 😀 is \ud83d\ude00. Leaving them unescaped is fine as long as the JSON is saved as UTF-8.
Example: put a message with quotes and a path into JSON
You need to send this three-line message (the example in the tool) as the message value of a JSON request:
Step 1: Escape it
The quotes became \", each backslash in the path doubled, and the line breaks and tab became \n and \t.
Step 2: Put it between the quotes
That is valid JSON. Any JSON reader gives back the original three lines, path and all.
How to unescape JSON
Switch the tool to Unescape and paste the escaped text, with or without its outer quotes. Error messages and stack traces in logs are the usual case: Error: \"timeout\"\n at fetch (app.js:12:5) becomes a readable message with real line breaks.
- Escaped JSON documents. If the result is JSON itself, the tool says so and formats it for you.
- Text escaped twice.
\\\"only becomes\"after one pass. The tool spots leftover escapes and offers to unescape again. - Invalid escapes.
\',\x41and a single backslash in a Windows path aren’t JSON. They are listed with their position instead of failing the whole text.
How to escape and unescape JSON in code
Each language’s JSON library escapes for you. To get just the escaped text, without the outer quotes:
// JavaScript
const escaped = JSON.stringify(text).slice(1, -1);
const plain = JSON.parse('"' + escaped + '"');
# Python
escaped = json.dumps(text, ensure_ascii=False)[1:-1]
plain = json.loads('"' + escaped + '"')
// C#
string escaped = JsonEncodedText.Encode(text, JavaScriptEncoder.UnsafeRelaxedJsonEscaping).ToString();
string plain = JsonSerializer.Deserialize<string>("\"" + escaped + "\"");
// Java (Jackson)
String escaped = new String(JsonStringEncoder.getInstance().quoteAsString(text));
String plain = new ObjectMapper().readValue("\"" + escaped + "\"", String.class);
// PHP
$escaped = substr(json_encode($text, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
$plain = json_decode('"' . $escaped . '"');The unescape lines are strict: they fail on a raw line break, a stray quote or \', which is where the tool above is more forgiving. To escape a whole JSON document into a quoted string in one step, see JSON Stringify.
Frequently asked questions
Do I need to escape forward slashes in JSON?
No. \/ is allowed but optional, and both read as /. PHP escapes slashes by default; most other languages don’t. It only matters when JSON sits inside an HTML <script> tag, where </ could end the script early.
Is \' a valid escape in JSON?
No. JSON strings use double quotes, so apostrophes never need escaping, and \' makes strict parsers fail. Write the apostrophe on its own.
What is the difference between escaping and stringifying JSON?
Escaping works on any text and gives you the inside of a JSON string, without quotes, ready to paste between them. Stringifying takes a whole JSON document and returns it as a complete quoted string. The escaping rules are the same.
How do I escape JSON for a URL?
JSON escaping doesn’t make text URL-safe: spaces, & and # still break a URL. Use percent-encoding instead, with JSON URL Encode or encodeURIComponent().
Sources
- RFC 8259, section 7: Strings: which characters must be escaped and how
- MDN: JSON.stringify(): escaping in JavaScript
- Python docs: json: json.dumps, json.loads and ensure_ascii
- Microsoft Learn: JsonEncodedText: escaping text in C#
- PHP manual: json_encode: slash and Unicode escaping flags
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.