Sanitizing Strings with the JSON Escaper
- Pick the Escape or Unescape tab depending on direction.
- Paste your text into the input panel - character counts update live.
- Click the action button to convert; the result appears in the output panel.
- Use Swap β
to send the output back to the input and flip the mode in one step.
JSON Escaper: escape text into a JSON string literal or unescape it back instantly. This string sanitization tool handles the strict requirements of JSON's grammar by applying backslash escaping to special characters. It is essential for developers who need to embed raw text, HTML, or SQL snippets within JSON-encoded payloads while ensuring a spec-correct JSON literal formatter result.
How This JSON Unescaper Operates
Our JSON Escaper uses a dual-method approach to handle complex decoding tasks. The unescape mode is implemented on top of JSON.parse, ensuring that \uXXXX unicode escapes and control characters like \b or \f are handled with technical precision. By providing a reliable double quote escaping and backslash escape mechanism, this free online tool simplifies the process of creating safe, round-trippable data formats without uploading secrets to a server.
- Escape mode covers the five JSON string escapes you actually hit (\\, \", \n, \r, \t)
- Unescape mode delegates to native JSON.parse for spec-correct decoding
- Swap β
flips both buffers and mode so round-trips don't double-escape
- Everything is local - useful when the string contains secrets you don't want uploaded
Frequently Asked Questions
When do I need to escape a string for JSON?
Whenever the string is going inside another JSON document - for example a SQL query stored in a JSON config file, or an HTML snippet inside a JSON API payload. JSON only allows certain characters raw inside string literals; everything else must be escaped with a backslash.
Why does unescape use JSON.parse?
Because reimplementing JSON's string grammar by hand misses cases like \u0041 unicode escapes and \b/\f. Wrapping your input in quotes and handing it to JSON.parse is the spec-correct decoder - and if it fails, the tool falls back to a regex-based unescape so common cases still work.
What about Unicode characters above U+FFFF?
JSON encodes them as a UTF-16 surrogate pair (\uD83D\uDE00 for π). The escape mode here does not force ASCII-only output, so emoji and other non-ASCII characters pass through verbatim. If you need pure ASCII, post-process with a \uXXXX escaper.
Why does Swap β
also flip the mode?
Because the natural workflow is: escape β use β paste back β unescape. Swapping the buffers without flipping the mode would re-escape an already-escaped string and double the backslashes.
Ensure your data is properly encoded by using this JSON Escaper for all your string sanitization and embedding requirements.