JSON String Escaper

Escape text for embedding inside a JSON string, or unescape a JSON string back to its raw text.

38Input characters
4Escape sequences

Everything you type here is processed on your own device. No input is sent to a server, logged, or stored.

What the JSON String Escaper does

The JSON string escaper on this page will escape text for embedding inside a JSON string, or unescape a JSON string back to its raw text. Paste your text in, pick the options you need, and copy the result straight back out. It is most often used for embedding a multi-line string inside a JSON config file. If you want to cross-check the result, there is another JSON string escaper on FreeToolsWorld.org.

How to use it

  1. Pick a direction.
  2. Paste the text to escape, or the escaped string to decode.
  3. Keep the quotes if you want a complete JSON string literal.
  4. Copy the result.

How it works

JSON requires escaping for the double quote, the backslash, and all control characters below U+0020. Newlines become \n, tabs \t, and anything else in that range becomes a \u sequence. Those are the only mandatory escapes.

The forward slash may optionally be escaped as \/ and frequently is, which is a holdover from embedding JSON inside HTML script tags — an unescaped </script> inside a string would otherwise terminate the element early. It is not required by the JSON specification.

Single quotes need no escaping in JSON, which trips up people coming from JavaScript source where both quote styles are string delimiters. JSON has only double quotes.

When to use it

  • Embedding a multi-line string inside a JSON config file.
  • Decoding an escaped string from a log or an API response.
  • Preparing text with quotes for a JSON payload.
  • Checking whether a string is correctly escaped.

Common mistakes to avoid

  • Escaping single quotes, which JSON does not require.
  • Forgetting that a literal backslash must itself be escaped.
  • Pasting a full JSON document into the unescaper, which expects a single string.

Frequently asked questions

What characters must be escaped in JSON?

The double quote, the backslash, and every control character below U+0020. Newline, tab, carriage return and a few others have short forms; the rest use \u notation.

Do I need to escape single quotes?

No. JSON strings are delimited by double quotes only, so a single quote is an ordinary character.

Why is the forward slash sometimes escaped?

To avoid an unescaped </script> inside a string terminating an HTML script element. It is optional under the JSON specification.

Related tools

See all developer tools →