Escape text for JSON, or read an escaped string back

Escape quotes, backslashes, line breaks and control characters so text fits in a JSON string, or unescape one back to plain text, with errors located.

How to escape a string for JSON

  1. 1

    Paste the text or the escaped string

  2. 2

    Choose escape or unescape

  3. 3

    Copy the result

Strings that drop straight into JSON

A message, an SQL query or a block of HTML cannot go into a JSON file as it is. Its quotation marks would end the string early and its line breaks are not allowed inside one. Escaping writes those characters as backslash sequences so the text fits between the quotes and reads back exactly.

Escape

The text is escaped with the browser’s own JSON.stringify, which writes what RFC 8259 requires and no more: \" for a quotation mark, \\ for a backslash, \n, \r, \t, \b and \f for those control characters, and \u00XX for the rest of U+0000 to U+001F. The result is wrapped in quotes, ready to paste as a value; untick the option to get the inside of the string only, for pasting between quotes you already have.

Tick the ASCII option to also write every non-ASCII character as a \u escape. An emoji, which lies outside the range four hex digits can reach, becomes two escapes, a surrogate pair, as JSON specifies.

Unescape

Paste an escaped string, with or without its surrounding quotes, and get the plain text back: \n becomes a line break, \u00e9 becomes é, and a surrogate pair becomes its emoji. The input is checked first, character by character, so an error says what is wrong and where, rather than “unexpected token”.

When to use something else

To check or tidy a whole JSON document, use the JSON formatter. For a value going into a URL rather than JSON, use URL encode, and for HTML, HTML entities.

Nothing is uploaded. The text is escaped in this tab.

Everything you need

Exactly what JSON needs

Quotes, backslashes and control characters escaped as RFC 8259 asks, and nothing else.

Errors located

Unescaping names the first bad escape, stray quote or raw line break and the character it is at.

Private by design

The text is escaped in your browser and never sent anywhere.

Nothing uploaded: open the Network panel while it runs and check.

No daily limits or watermarks: free batches take up to 20 images.

Works offline: once the page has loaded, on any current browser.

Frequently asked questions

Which characters does JSON require to be escaped?

Only three kinds. The quotation mark, the backslash, and the control characters U+0000 to U+001F, which include line breaks and tabs. Everything else, accented letters and emoji included, can stay as it is in a UTF-8 file.

Should a slash be escaped?

It may be written as \/ but does not have to be, and the escape here leaves it as /. Reading back accepts both, since RFC 8259 lists \/ among the allowed escapes.

What does the ASCII option do?

It writes every character past the ASCII range as \u followed by four hexadecimal digits, and an emoji as a pair of them. The JSON then contains only ASCII, which helps when it passes through a system that mangles UTF-8.

Why does unescaping fail?

Because the text is not a valid JSON string. The message gives the first problem and where it is, such as an unescaped quote at character 12, a \x escape JSON does not have, or a line break that should be written \n.

Sources

Related guides

Work with files privately and confidentlyPractical, sourced explanations for safer file conversion, sharing, and cleanup.