How to use the JSON String Escape
Escape a JSON string in three steps:
1
Paste your text
Enter the raw text you want to use as a JSON string value.
2
Choose output wrapping (optional)
Toggle 'Wrap in quotes' to get the complete "escaped value" output. Toggle 'Wrap as {"value": "..."}' to get a ready-to-use JSON object.
3
Copy and paste into your JSON
Copy the escaped output and paste it between the double quotes in your JSON document.
When to use this tool
Use this tool when you need to embed text safely inside a JSON string value:
- →Escaping multi-line text or text with quotes before embedding it in a JSON string field
- →Preparing user-generated content for safe inclusion in a JSON API request body or configuration file
- →Escaping code snippets, file paths, or other technical strings that contain backslashes and quotes for JSON storage
- →Fixing JSON parse errors caused by unescaped characters inside string values
- →Generating JSON configuration files programmatically where string values may contain special characters
- →Escaping strings to embed in JSON PATCH requests, GraphQL variables, or REST API JSON payloads
Frequently asked questions
Q:What characters must be escaped in JSON string values?
Per RFC 8259, exactly these characters must be escaped in JSON strings: (1) double quote (") → \"; (2) backslash (\) → \\; (3) control characters U+0000–U+001F, which include the shorthand sequences \b (backspace, U+0008), \t (tab, U+0009), \n (newline, U+000A), \f (form feed, U+000C), \r (carriage return, U+000D), and all other control characters encoded as \uHHHH. All other characters — including single quotes, angle brackets, non-ASCII letters, and emoji — do not need to be escaped in JSON, although they may be escaped as \uHHHH optionally.
Q:Why should I use a JSON escape tool instead of JavaScript's JSON.stringify()?
JSON.stringify() in JavaScript escapes a complete value including its surrounding quotes and also handles nested objects and arrays. This tool escapes just the string content for use between existing JSON quotes — it's useful when you're editing a JSON file manually, working in an environment without JavaScript, generating JSON in a server-side language, or pasting text into an existing JSON structure where you need to escape just the value without re-serializing the whole document. For programmatic serialization in code, JSON.stringify() is always the correct choice.
Q:Does JSON require escaping forward slashes?
No — JSON does not require forward slashes (/) to be escaped. The JSON specification (RFC 8259) permits forward slashes unescaped in string values. However, JSON.stringify() in some older browsers and some JSON libraries optionally escape forward slashes as \/ to prevent the sequence </script> from appearing in JSON embedded in HTML pages. This is a precaution for HTML embedding, not a JSON requirement. This tool does not escape forward slashes, following the RFC 8259 standard. If you need slash escaping for HTML embedding, the HTML Encoder tool is more appropriate.
Q:Why does JSON only support \uHHHH for Unicode escapes, not \u{HHHH}?
The JSON specification was finalized in 2006 before ES6 introduced \u{HHHH} syntax in 2015. JSON's original design supports only the 4-digit \uHHHH form, which is limited to the Basic Multilingual Plane (U+0000 to U+FFFF). Characters above U+FFFF (emoji, supplementary scripts) must be encoded as UTF-16 surrogate pairs — two consecutive \uHHHH sequences. For example, 😀 (U+1F600) in JSON must be encoded as \uD83D\uDE00. All JSON parsers handle this correctly. Alternatively, emoji and supplementary characters can appear as literal UTF-8 in JSON files, which all modern parsers handle.
Q:What happens if I don't escape special characters in JSON?
Unescaped special characters in JSON string values cause JSON parse errors. A double quote without a backslash prefix terminates the string early, making the rest of the value invalid JSON. An unescaped newline (actual line break) in a JSON string value makes the JSON technically invalid per the spec (though some lenient parsers accept it). Unescaped backslashes followed by unrecognized characters (like \p) may cause parser errors or be silently ignored depending on the implementation. JSON parsing is unforgiving — a single unescaped character can cause an entire document to fail to parse.
Q:How is JSON escaping different from HTML entity encoding?
JSON escaping uses backslash-based escape sequences (\n, \", \uHHHH) and is designed for use inside JSON string values in data interchange. HTML entity encoding uses ampersand-based sequences (<, &, ©) and is designed for displaying text as content in HTML documents. They serve completely different contexts: JSON escaping prevents JSON parse errors, while HTML encoding prevents HTML injection and XSS. If you need to store HTML content in a JSON field, you would apply JSON escaping to the already-HTML-encoded string — both layers are independent and cumulative.