JSON Escape Tool
Escape special characters to create valid JSON strings. Paste your text below:
Escape Reference
\"\\\n\t\r\bWhat is JSON Escaping?
JSON strings have strict rules about special characters. Certain characters must be "escaped" with a backslash to be included in a JSON string. This tool automatically converts raw text into a properly escaped JSON string value.
Characters That Need Escaping
The JSON specification requires these characters to be escaped:
| Character | Escaped | Description |
|---|---|---|
" | \" | Double quote — must be escaped inside strings |
\ | \\ | Backslash — the escape character itself |
| Newline | \n | Line feed (LF) |
| Tab | \t | Horizontal tab |
| Carriage return | \r | CR (often paired with \n on Windows) |
| Backspace | \b | Rarely used |
| Form feed | \f | Page break (legacy) |
Example
Raw text:
Hello "World"
Line 2 with tabAfter escaping:
"Hello \"World\"\nLine 2 with\ttab"When to Use This Tool
- Building JSON manually — When concatenating strings into JSON
- Embedding text in JSON — Multi-line content, quotes in values
- API request bodies — Ensuring special characters don't break requests
- Configuration values — File paths with backslashes
- Debug JSON issues — Finding problematic characters
Escaping vs Stringify
This tool escapes a raw string. If you want to convert an entire JavaScript object to a JSON string, use JSON Stringify instead. The difference:
- Escape: raw text → escaped string value
- Stringify: JavaScript object → complete JSON
Options Explained
Wrap in quotes
Enable this to get a complete JSON string value with surrounding quotes. Disable it if you only need the escaped content to insert into an existing JSON structure.
Escape Unicode
When enabled, non-ASCII characters (é, 中, 🎉) are converted to \uXXXX format. This ensures compatibility with systems that don't support UTF-8, though modern JSON parsers handle Unicode natively.
Escaping in Code
In most cases, you should use your language's JSON library instead of manual escaping:
JavaScript
// Don't do this:
const json = '{"name": "' + name + '"}';
// Do this instead:
const json = JSON.stringify({ name: name });
// Or just the string:
const escaped = JSON.stringify(text);Python
import json
# Escape a string
escaped = json.dumps(text)
# Build complete JSON
data = json.dumps({"name": text})Why use libraries?
JSON libraries handle all edge cases correctly — Unicode, control characters, and encoding issues. Manual string building is error-prone and can create security vulnerabilities.
Common Mistakes
Forgetting to escape backslashes
Windows file paths like C:\Users\Name need double backslashes:C:\\Users\\Name
Not escaping quotes
A value containing " breaks the JSON structure unless escaped as \"
Raw newlines in strings
Multi-line strings must use \n — literal newlines are invalid in JSON strings
Related Tools
- JSON Unescape — Reverse: convert escaped strings back to raw text
- JSON Stringify — Convert objects to JSON strings
- JSON Validator — Validate your JSON after building it
- Common JSON Mistakes — Avoid escaping errors
Frequently Asked Questions
What's the difference between escape and stringify?
Escape converts raw text into a valid JSON string value. Stringify converts an entire JavaScript object into a JSON string. Use escape for embedding text; use stringify for converting objects.
Do I need to escape forward slashes?
No. Forward slashes (/) are valid in JSON strings without escaping. Some tools escape them as \/ for HTML compatibility, but it's optional.
How do I escape Unicode characters?
Enable the "Escape Unicode" option to convert characters like é to\u00e9. This is only needed for legacy systems — modern JSON parsers handle UTF-8 natively.
Common Mistakes & Pro Tips
- Escaping makes a raw string safe inside JSON quotes — It replaces characters that JSON forbids in string values with their escape sequences: " becomes \", \ becomes \\, and newline becomes \n. The result is the inner content of a JSON string, ready to drop between double quotes.
- Only specific characters must be escaped — RFC 8259 requires escaping the double quote, the backslash, and the U+0000 through U+001F control characters; everything else may appear literally. So letters, spaces, and most punctuation pass through unchanged, while a tab or newline becomes \t or \n.
- Control characters need \uXXXX when they have no short form — JSON defines short escapes for \b, \f, \n, \r, and \t, but other control characters like U+0001 or U+007F-region nuances must use the six-character \u00XX form. A correct escaper emits \u0001 rather than leaving a raw, illegal control byte in the string.
- Escaping is not encoding and not stringify — Escaping only neutralizes JSON-unsafe characters within a string's content; it does not add outer quotes (that is stringify's job) and is unrelated to URL or HTML encoding. Mixing these up leads to data that is either still invalid or wrongly transformed.
- The forward slash does not require escaping — Although \/ is a legal JSON escape, the / character is perfectly valid unescaped, so escaping it is optional. Some tools escape it to avoid the </script> sequence when JSON is embedded in HTML, but for plain JSON it is unnecessary.
Frequently Asked Questions
What exactly does escaping a string do?
It rewrites the characters that are illegal or ambiguous inside a JSON string value so the string can sit safely between double quotes. Quotes, backslashes, and control characters get their escape sequences, while ordinary text is left as-is. The output is the safe inner content of a JSON string.
How is escaping different from JSON.stringify?
Stringify takes any JSON value and returns a complete quoted literal, including the outer quotes and value-to-text conversion. Escape works on raw string content only and produces the escaped characters without necessarily wrapping them in quotes. For a plain string, stringify is roughly escape plus surrounding quotes.
Which characters actually have to be escaped?
Per RFC 8259, only the double quote ("), the backslash (\), and control characters U+0000 to U+001F are required to be escaped inside a JSON string. Common control characters use short forms like \n, \r, and \t; the rest use \uXXXX. All other Unicode characters may appear literally.
How do I safely put a multi-line string into JSON?
Escape it first so each line break becomes \n (and carriage returns become \r), because JSON strings cannot contain literal newlines. After escaping, the entire multi-line text becomes a single valid JSON string value that round-trips back to the original lines when parsed.
Do I need to escape non-ASCII or emoji characters?
No. JSON strings are Unicode, so characters like accented letters or emoji are valid as-is when the document is UTF-8. You may optionally escape them as \uXXXX for ASCII-only transport, but it is not required for correctness.
Is my input sent anywhere when I escape it?
No. Escaping runs locally in your browser, so the raw string you paste, which might contain secrets or log data, is processed on your device and never uploaded. You can safely escape sensitive content here.