Escape special characters in JSON strings or unescape previously escaped JSON. Handles backslashes, double quotes, newlines, tabs, Unicode sequences, and all control characters defined by the JSON specification. Free and instant.
The JSON specification (ECMA-404 / RFC 8259) requires that string values inside a JSON document use double quotes as delimiters. This creates a conflict: if a string value itself contains a double quote, a backslash, or a control character like a newline, the JSON parser will misread it unless those characters are escaped.
Escaping means inserting a backslash (\) before the special character, transforming it into a two-character escape sequence that the parser knows to treat as a literal character rather than as JSON syntax.
For example, this is invalid JSON because the inner quote breaks the string boundary:
{ "message": "He said "hello" to me" }
This is the valid, escaped version:
{ "message": "He said \"hello\" to me" }
Every escape sequence defined by the JSON specification:
| Character | Escape Sequence | Description |
|---|---|---|
" | \" | Double quote |
\ | \\ | Backslash (reverse solidus) |
| newline | \n | Line feed (LF, U+000A) |
| carriage return | \r | Carriage return (CR, U+000D) |
| tab | \t | Horizontal tab (U+0009) |
| backspace | \b | Backspace (U+0008) |
| form feed | \f | Form feed (U+000C) |
| any Unicode | \uXXXX | Unicode code point (4 hex digits) |
| / | \/ | Forward slash (optional, but valid) |
Unicode escapes use the form \uXXXX where XXXX is a four-digit hexadecimal code point. For example, \u00e9 represents the character Γ©, and \u4e2d represents the Chinese character δΈ. Surrogate pairs (\uD800β\uDFFF) are used to encode characters outside the Basic Multilingual Plane.
JSON escaping is required in several practical situations:
\n.C:\Users\Alice\file.txt. In JSON this must be written as C:\\Users\\Alice\\file.txt.\d, \w, etc.) that must be doubled in JSON.This pattern appears frequently in logging, message queues, and API gateways that wrap inner payloads as strings. The inner JSON object must have all its double quotes escaped:
{
"event": "user_action",
"payload": "{\"userId\":42,\"action\":\"login\",\"timestamp\":\"2026-03-05T10:00:00Z\"}"
}
When building SQL INSERT or UPDATE statements that store JSON in a TEXT/JSONB column, you need to escape the JSON string for the SQL context as well as ensure the JSON itself is valid:
INSERT INTO logs (data) VALUES ('{"user":"alice","action":"login"}');
PostgreSQL's JSONB column accepts valid JSON directly. MySQL requires the string to be properly quoted within the SQL statement. Always use parameterized queries to avoid both SQL injection and escaping issues.
Embedding JSON in HTML data-* attributes requires HTML-encoding the double quotes as ":
<div data-config='{"theme":"dark","lang":"en"}'></div>
<!-- Or with double-quote attributes, HTML-encode: -->
<div data-config="{"theme":"dark"}"></div>
Using single quotes for the HTML attribute (as in the first example) avoids the need to HTML-encode the inner JSON double quotes, which is the simpler approach when embedding JSON directly in HTML.
When writing JSON inside a JavaScript string (rather than a JS object literal), the quotes need escaping:
// Correct: use JSON.stringify instead of manual escaping
const jsonString = JSON.stringify({ user: "alice", active: true });
// Produces: '{"user":"alice","active":true}'
JSON strings must be enclosed in double quotes, so any double quote inside the string value must be escaped as \" to prevent the JSON parser from treating it as the end of the string. Similarly, backslashes, newlines, and control characters must be escaped so the JSON remains valid and parseable by any standards-compliant parser.
The JSON specification requires escaping of: double quote (\"), backslash (\\), and control characters including newline (\n), carriage return (\r), horizontal tab (\t), form feed (\f), and backspace (\b). Any Unicode character can also be escaped as \uXXXX using its four-digit hex code point.
JSON escaping refers to adding backslash sequences inside a JSON string value so special characters are treated as literal text rather than syntax. Encoding often refers to serializing an entire value or object into a JSON string representation (for example JSON.stringify in JavaScript). They solve different problems: escaping makes a string safe inside JSON, while encoding converts a data structure into a JSON-formatted string.
To embed JSON as a string value inside another JSON document, you must escape all double quotes with \" and all backslashes with \\. For example, the JSON object {"key":"value"} becomes the string "{\"key\":\"value\"}" when embedded. Our escape tool handles this automatically β paste your inner JSON and it produces the correctly escaped string.
Free, browser-only tool. Your data is never sent to a server.
JSON requires certain characters within strings to be escaped with a backslash. Understanding these rules is critical when embedding JSON in HTML, URLs, or shell commands.
| Character | Escaped | Notes |
|---|---|---|
| " | \" | Double quote β delimiter for JSON strings |
| \ | \\ | Backslash β escape character itself |
| / | \/ | Forward slash β optional but recommended in HTML |
| Newline | \n | Line feed character (U+000A) |
| Tab | \t | Horizontal tab (U+0009) |
| Carriage return | \r | Carriage return (U+000D) |
| Backspace | \b | Backspace (U+0008) |
| Form feed | \f | Form feed (U+000C) |
| Unicode | \uXXXX | Any Unicode code point (4 hex digits) |
// Raw string
He said "Hello\nWorld" and left
// JSON escaped
"He said \"Hello\\nWorld\" and left"
// JavaScript
const escaped = JSON.stringify(rawString);
const unescaped = JSON.parse(escaped);
Also useful: JWT Decoder | JSON Validator | JSON Formatter | JSONPath Tutorial | JSON Schema Examples
Every escape sequence defined in the JSON specification (RFC 8259), with Unicode code points and usage notes:
| Escape Sequence | Character | Unicode | Description |
|---|---|---|---|
\" |
Double quote | U+0022 | Required inside JSON string values |
\\ |
Backslash | U+005C | Literal backslash character |
\/ |
Forward slash | U+002F | Optional but valid; safe for HTML in JSON |
\n |
Newline | U+000A | Line feed / newline character |
\r |
Carriage return | U+000D | Used in Windows-style line endings |
\t |
Tab | U+0009 | Horizontal tab |
\b |
Backspace | U+0008 | Backspace character |
\f |
Form feed | U+000C | Form feed / page break |
\uXXXX |
Unicode | any | Any Unicode code point as 4-digit hex |
Real-world JSON escaping comes up in three situations that developers encounter regularly. Here are canonical examples with before and after:
When an inner JSON object needs to be stored as a string value inside an outer JSON document (common in logging, message queues, and API gateways):
// Original JSON to embed
{"name": "Alice", "role": "admin"}
// Embedded as a string value in outer JSON
{"config": "{\"name\": \"Alice\", \"role\": \"admin\"}"}
Strings containing newlines and quotes must use escape sequences to remain valid JSON:
// String with newlines and quotes
{"message": "Line 1\nLine 2\nShe said \"hello\" to him."}
Regex patterns often contain backslashes that must be double-escaped in a JSON string:
// Backslashes in regex must be double-escaped in JSON
{"pattern": "^\\d{4}-\\d{2}-\\d{2}$"}
// This represents the regex: ^\d{4}-\d{2}-\d{2}$
These three encoding methods solve different problems and are often confused. Use this table to choose the right one:
| Aspect | JSON Escape | URL Encode | HTML Encode |
|---|---|---|---|
| Purpose | Make string safe inside JSON | Make string safe in URL query params | Make string safe in HTML |
| Double quote | \" |
%22 |
" |
| Space | Kept as-is | %20 or + |
Kept as-is |
| Ampersand | Kept as-is | %26 |
& |
| Newline | \n |
%0A |
|
| Backslash | \\ |
%5C |
Kept as-is |
| Use case | JSON string values | URL query strings | HTML attribute values |
When you receive a JSON payload that was double-encoded β or a JSON string stored inside another JSON string β it contains visible escape sequences like \n, \", \\. Unescaping converts these back to their literal characters.
| Escaped (Input) | Unescaped (Output) |
|---|---|
| {\"name\":\"Alice\",\"city\":\"New York\"} | {"name":"Alice","city":"New York"} |
| Line 1\nLine 2\nLine 3 | Line 1 Line 2 Line 3 |
| path\\to\\file | path\to\file |
| \u0048\u0065\u006C\u006C\u006F | Hello |
Every major language provides built-in methods for JSON string escaping and unescaping:
// Escape a string for embedding in JSON
const escaped = JSON.stringify(rawString);
// Unescape a JSON string back to plain text
const unescaped = JSON.parse('"' + escapedString + '"');
// Example
const raw = 'Hello "World"\nLine 2';
const esc = JSON.stringify(raw); // "Hello \"World\"\nLine 2"
const back = JSON.parse(esc); // Hello "World"\nLine 2
import json
raw = 'Hello "World"\nLine 2'
escaped = json.dumps(raw) # '"Hello \\"World\\"\\nLine 2"'
unescaped = json.loads(escaped) # Hello "World"\nLine 2
<?php
$raw = 'Hello "World"' . "\nLine 2";
$escaped = json_encode($raw); // "Hello \"World\"\nLine 2"
$unescaped = json_decode($escaped); // Hello "World"\nLine 2
Also useful: JSON Validator | JSON Stringify / Parse | Base64 JSON | JSON Repair