Escape JSON
Escape special characters in JSON strings. Handles quotes, backslashes, newlines, tabs, and Unicode. 100% client-side.
Paste in raw text with quotes, backslashes, newlines, or tabs and get back a properly escaped string that won't break your JSON. Handles Unicode and surrogate pairs too — toggle options for wrapping in quotes or forcing \uXXXX notation. And everything runs in your browser. Nothing gets uploaded.
How It Works
The tool scans each character in your input against the JSON specification. Control characters (codes below 32), backslashes, and double quotes all get their proper escape sequences. If you turn on Unicode escaping, anything above code point 127 gets converted to \uXXXX notation — including surrogate pairs for emoji and CJK characters. The output updates instantly and shows you byte sizes plus how many characters were escaped.
Examples
Escaping a User Comment with Quotes
A user submits a review containing double quotes. You need it safe for a JSON API payload.
She said "this is great!" and left.
She said \"this is great!\" and left.
Multi-line Address for a Config File
Addresses with line breaks need newline escaping before they can sit inside a JSON value.
742 Evergreen Terrace
Springfield, IL 62704
USA
742 Evergreen Terrace\nSpringfield, IL 62704\nUSA
Windows File Path with Backslashes
Storing a Windows path in JSON? Every single backslash needs doubling. Miss one and the parser breaks.
C:\Users\Documents\report.pdf
C:\\Users\\Documents\\report.pdf
Who Uses This
Prepping user-submitted text for JSON API responses without writing escape logic by hand.
Escaping multi-line values for JSON config files, environment variables, or CI/CD templates.
Creating test payloads with special characters to check how APIs handle edge-case inputs.
Embedding code snippets with quotes and backslashes into JSON-based documentation systems.
Common Mistakes
If your string already has \" in it and you escape again, you get \\\". Double-escaping is the number one cause of garbled JSON output. Always start with the raw, unescaped version.
Text pasted from Word or PDF files often carries hidden characters — zero-width spaces, soft hyphens, or form feeds. They won't show up in your editor but will crash a strict JSON parser. This tool catches and escapes all of them.
Unicode escaping converts é to \u00e9 — useful for ASCII-only systems, but it bloats your output and makes it harder to read. If your stack handles UTF-8 (most do), keep it off.
Technical Details
- Processing: 100% client-side — JavaScript only, no server calls
- Browser Support: Chrome, Firefox, Safari, Edge
- Spec Compliance: Follows RFC 8259 (JSON) escape rules
- Unicode: Full surrogate-pair support for characters outside the Basic Multilingual Plane
- Max Input: Limited only by your browser's memory
Frequently Asked Questions
What characters need to be escaped in JSON?
The JSON spec (RFC 8259) requires escaping double quotes, backslashes, and all control characters with code points below U+0020. That covers newlines, tabs, carriage returns, backspaces, and form feeds. Everything else is technically valid in a UTF-8 encoded JSON string, though you can optionally escape non-ASCII characters too.
How do I escape a JSON string in JavaScript?
The quickest way is JSON.stringify(yourString) — it handles all required escaping automatically. But if you need finer control (like forcing Unicode escapes or skipping the outer quotes), a manual character-by-character scan like this tool uses gives you more flexibility.
What is the difference between JSON escape and URL encode?
Different jobs entirely. JSON escaping uses backslash sequences (\", \n, \uXXXX) to make text safe inside JSON strings. URL encoding uses percent sequences (%20, %22) to make text safe in URLs. You'd use JSON escaping when building API payloads and URL encoding when constructing query strings.
Can I escape JSON with special characters like emoji?
Yes. Emoji are valid in JSON strings as-is when the file is UTF-8 encoded. If you need ASCII-safe output, turn on Unicode escaping here — the tool converts emoji into surrogate pair notation (two \uXXXX sequences). Most modern systems handle raw emoji fine, so you only need this for legacy compatibility.
Is there a size limit for JSON strings?
The JSON spec itself doesn't set a maximum string length. In practice, your limit is whatever the receiving parser or system allows. This tool runs in your browser, so it can handle several megabytes of text without trouble. For really massive strings (50MB+), a command-line tool or library would be faster.