JSON escape
Escape text for JSON in your browser: nothing is uploaded, there is no limit on the length, and the result is exactly what JSON.stringify produces, ready to put between the quotes of a JSON string.
How it works
-
Paste your code
Paste the code in the left box or open a file. No code to hand? Click Example.
-
Instant result
The result appears as you type. If there is an error, you see the line and character.
-
Copy or download
Copy the result with one click or save it as a file for your editor or project.
What gets escaped?
Double quotes become \", backslashes \\, line breaks \n, tabs \t and other control characters \uXXXX. Everything else stays as it is, including accents and emoji, because JSON is UTF-8 anyway.
Options
- With quotes around it gives a complete JSON string value, including the outer
". - Everything outside ASCII as \uXXXX writes é as
\u00e9and emoji as two\ucodes. Use this when the file or system can't handle UTF-8.
Single quotes don't need escaping in JSON, so they stay as they are. To go back, use JSON unescape.
When you need to escape
- A message with line breaks in an API request. A real line break inside a JSON string is invalid; it has to be
\n. - Embedding code or HTML in JSON, such as an email template, a configuration value or a webhook body.
- JSON inside JSON. A JSON document that is stored as a string field has to be escaped completely, quotes included. Escape it once for each level of nesting.
- Test data for a unit test or a Postman request body.
Be careful with double escaping
If you escape text that is already escaped, every backslash is doubled and \n becomes \\n, which decodes to a literal backslash and an n instead of a line break. If the output looks full of backslashes, you probably escaped twice. JSON unescape gives you the original back.
Not the same as escaping for other languages
JSON escapes are close to JavaScript string escapes, but not identical to those of SQL, shell, XML or Python. Use the escaping that belongs to where the text ends up, and use HTML entities for HTML.
Frequently asked questions
Do I need to escape single quotes in JSON?
No. JSON strings use double quotes, and single quotes are allowed unescaped.
Why are my accented letters turned into \u codes?
Only if you choose the ASCII-only option. Normally accents and emoji stay as they are, since JSON is UTF-8.
Is the output the same as JSON.stringify?
Yes, for the string content. It matches what JSON.stringify writes between the quotes.
Is my text uploaded?
No. It is escaped in your browser and never sent anywhere.