About JSON String Escaper
Putting a paragraph, a file path, a SQL query or a snippet of HTML into a JSON value means escaping every double quote, backslash and line break, and one missed character breaks the whole document. Paste the text here and it comes back as a JSON string literal you can drop straight into a file or a request body.
You can leave out the surrounding quotes, and escape every character outside ASCII as \u sequences for systems that cannot take UTF-8. Switch the direction, or use the swap button, to turn a JSON string back into plain text.
How it works
- Escaping uses the browser’s own JSON writer, so the result is exactly what JSON.stringify would produce: \" for quotes, \\ for backslashes, \n and \t for line breaks and tabs, \u0001 style escapes for other control characters.
- With non-ASCII escaping on, every character above U+007E is written as \u followed by four hexadecimal digits; characters outside the Basic Multilingual Plane, such as emoji, become two of them.
- In the other direction the literal is checked character by character first, so a mistake is reported with its line and column, then decoded.
Questions
Why are forward slashes not escaped?
JSON allows \/ but does not require it, and JSON.stringify leaves slashes alone. The result is valid either way; when unescaping, \/ is understood.
What is a lone surrogate?
Half of a character such as an emoji, which in JSON takes two \u escapes. Text cut in the middle of one can contain a half. Escaping writes it as a \u escape so the JSON stays valid; unescaping keeps it and warns you.
Can I unescape a string copied from a log, without its quotes?
Yes. If the text does not start and end with a double quote it is read as the inside of a string, and line breaks at either end are ignored.
How long can the text be?
Up to 5 MB. The conversion happens in this browser tab and the text is never sent anywhere.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.