JSON Escape Unescape

Escape or unescape JSON string content. Convert special characters to JSON-safe escape sequences and back.

  1. Home
  2. > Encoder & Decoder >
  3. JSON Escape / Unescape

Escape

Unescape

What is JSON Escaping?

JSON escaping is the process of converting special characters in a string to their JSON-safe escape sequences. According to the JSON specification (RFC 7159), certain characters must be escaped when they appear inside a JSON string: the double quote ("), backslash (\\), and control characters (U+0000 through U+001F).

For example, the string He said "Hello" becomes He said \"Hello\" when escaped for JSON. The tab character becomes \t, newline becomes \n, and carriage return becomes \r.

Common JSON Escape Sequences

CharacterEscape SequenceDescription
"\"Double quote
\\\\\\Backslash
/\\/Forward slash (optional)
\b\\bBackspace
\f\\fForm feed
\n\\nNewline
\r\\rCarriage return
\t\\tTab
U+0000-U+001F\\uXXXXControl characters

How to Use This JSON Escape/Unescape Tool

  1. Escape — Type or paste raw string content into the left panel, then click Escape to convert special characters to JSON-safe sequences.
  2. Unescape — Type or paste escaped JSON string content into the right panel, then click Unescape to revert escape sequences to their actual characters.
  3. Options — Toggle Escape forward slashes, Escape non-ASCII as \uXXXX, or Wrap output in quotes.
  4. Swap & Clear — Click Swap to exchange escape/unescape values, Clear All to reset everything.

Common Use Cases

  • API development — Escape string values before embedding them in JSON request/response bodies.
  • Debugging JSON logs — Unescape escaped JSON in log files to read the actual content.
  • Database storage — Ensure JSON strings stored in databases are properly escaped.
  • Configuration files — Prepare string values with special characters for JSON config files.
  • Data interchange — Properly escape text data when transferring between systems using JSON.

Frequently Asked Questions

Is this the same as JSON.stringify?

This tool produces similar output to JavaScript's JSON.stringify() but gives you more control. You can choose whether to escape forward slashes, escape non-ASCII characters as \\uXXXX, and wrap the output in double quotes.

Why escape forward slashes?

Escaping forward slashes (\\/) is optional in JSON but was required in older JSON specifications. Some applications (especially those embedding JSON in HTML <script> tags) still escape slashes to prevent </script> injection.

What characters does JSON require to be escaped?

The JSON specification requires that the double quote (") and backslash (\\) be escaped, and all control characters (U+0000 through U+001F) be escaped as well. Control characters are escaped as \\n, \\t, etc., or as \\uXXXX for others.

Can I use this for JSONP or embedded JSON?

Yes. The Escape forward slashes option is especially useful for JSONP or JSON embedded in HTML <script> tags, as it prevents injection attacks via closing tags like </script>.

What is the difference between JSON escape and URL escape?

JSON escape converts characters to backslash sequences (\\n, \\") for use inside JSON strings. URL escape (percent encoding) converts characters to %XX sequences for use in URLs. They serve different purposes and use different encoding schemes.

Help2Code Logo
Menu