JSON Escape

Escape special characters in JSON strings.

Local Your input is processed locally in your browser. Found a problem? Report an issue

What JSON Escape does

JSON Escape turns text into the inside of a JSON string value, following RFC 8259: the double quote and the backslash get a backslash in front, and control characters (U+0000 to U+001F) become short escapes such as \n or a \u00XX code.

Everything else is left as typed, including accented letters and emoji, because JSON text is UTF-8 and every JSON parser reads them directly. The output has no surrounding quotes, so it can be pasted between the quotes of an existing value.

JSON Escape examples

The built-in sample

Input

say "hello" & <b>bye</b>

Output

say \"hello\" & <b>bye</b>

This is the input that the Load sample button fills in.

Line breaks and control characters

Input

Tab	here
next line ␁ end

Output

Tab\there\nnext line \u0001 end

The tab and line break become \t and \n. U+0001 has no short form, so it becomes \u0001.

Unicode stays as it is

Input

Zoë says "hi" 😀

Output

Zoë says \"hi\" 😀

Only the quotes change. ë and the emoji are valid JSON as they are.

Each output was produced by running this tool on the input above it. Invisible control characters are shown as symbols, for example ␁ for U+0001 and ␀ for U+0000.

How it works

Each character is checked against the rules below; all other characters are copied unchanged.

CharacterWritten as
"\"
\\\
line break (U+000A)\n
carriage return\r
tab\t
backspace\b
form feed\f
other U+0000 to U+001F\u0001 (four hex digits)

Details and limits

  • The forward slash and the apostrophe are not escaped: neither is special in JSON. \/ is allowed but never needed.
  • Need ASCII-only output, for example for a file whose encoding you cannot control? Java Escape writes every non-ASCII character as \uXXXX, which JSON also accepts.
  • To go the other way, use JSON Unescape.

Questions

Is my data uploaded when I use JSON Escape?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does JSON Escape do?

JSON Escape turns text into the inside of a JSON string value, following RFC 8259: the double quote and the backslash get a backslash in front, and control characters (U+0000 to U+001F) become short escapes such as \n or a \u00XX code.

Are there any limits I should know about?

The forward slash and the apostrophe are not escaped: neither is special in JSON. \/ is allowed but never needed. Need ASCII-only output, for example for a file whose encoding you cannot control? Java Escape writes every non-ASCII character as \uXXXX, which JSON also accepts.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.