Skip to content
AgileLogics

JSON Escape / Unescape

Escapes special characters (quotes, backslashes, newlines) for safe embedding in a JSON string, or reverses the process.

Working on a whole file? Open it in the JSON editor →

How it works

Type or paste text, choose a direction, and click Convert.

How do you escape a string for JSON?

Put a backslash in front of every double quote and every backslash, and replace control characters such as line breaks and tabs with escape codes like \n and \t. The result can sit safely between the quotes of a JSON string value. This tool does that in Escape mode, and Unescape mode reverses it, turning line1\nline2 back into two lines of text.

The rules come from section 7 of RFC 8259, the JSON specification, and they're short: the double quote, the backslash and the 32 control characters from U+0000 to U+001F must be escaped. Nothing else has to be.

The escape sequences

Character Escaped form Produced by Escape mode?
" \" Yes
\ \\ Yes
Line feed \n Yes
Carriage return \r Yes
Tab \t Yes
Backspace, form feed \b, \f Yes
Other control characters \u0000 to \u001f Yes, e.g. \u0007 for the bell character
/ \/ No, but Unescape accepts it
Any character \uXXXX Only for control characters and broken surrogate halves; Unescape accepts any

Escape mode uses the same rules as JavaScript's JSON.stringify, minus the outer quotes. Characters outside ASCII are left alone, so café 👍 comes out unchanged.

Escaping text to put in JSON

  1. Leave Direction on Escape.
  2. Paste the raw text, including any quotes, backslashes or line breaks.
  3. Click Convert.
  4. Paste the output between the quotes of your JSON value.

Three typical inputs and what you get back:

Raw text Escaped
She said "hi" She said \"hi\"
C:\Users\me C:\\Users\\me
Line 1 and Line 2 on separate lines Line 1\nLine 2

The second row is the one that bites most often. Windows paths, regular expressions and LaTeX all contain backslashes, and each one has to be doubled. A JSON snippet such as {"path": "C:\Users\me"} is invalid, and a parser will reject it at the \U.

Hand-built JSON is where this matters: request bodies for curl, test fixtures, config files, or a value copied into a database column. If you're building JSON in code, let the language's serializer do the escaping instead.

Unescaping a string from a log or API response

Logs and API errors often show JSON strings in their escaped form, with \n instead of line breaks and \" around quoted words. To read one:

  1. Switch Direction to Unescape.
  2. Paste the text that sat between the quotes, without the quotes themselves.
  3. Click Convert.

{\"name\": \"Ann\"} unescapes to {"name": "Ann"}, which is handy when one JSON document has been stored as a string inside another. Unicode escapes are decoded as well: Price: \u20AC5 becomes Price: €5, and a surrogate pair such as \ud83d\udc4d becomes the emoji it encodes.

When unescaping fails

Unescape mode wraps your input in quotes and parses it as a JSON string, so anything a JSON parser would reject gives "Enter a valid JSON-escaped string (without the surrounding quotes)." The usual causes:

  • Surrounding quotes included. "hello" becomes ""hello"" internally, which isn't valid. Delete the outer quotes.
  • A bare double quote. bad "quote has an unescaped " in the middle. In valid escaped text every quote is written \".
  • A lone or unknown backslash escape. C:\Users, \x41 and \' all fail. JSON has no \x or \' escapes, even though JavaScript and Python do.
  • Real line breaks or tabs. JSON strings can't contain raw control characters, so text pasted across several lines, or containing an actual tab, is rejected. In escaped text they should already appear as \n and \t.

If you need to check an entire document rather than one string, paste it into the JSON validator, which reports where parsing stops.

Related tools

Once your string is escaped, the JSON formatter lays out the full document for reading, and the JSON editor lets you edit it with syntax highlighting. If the text is going into a web page rather than JSON, the escaping rules are different, so use the HTML encoder instead.

Last updated

Frequently asked questions

Which characters must be escaped in a JSON string?
RFC 8259 requires three groups: the double quote, the backslash, and the control characters U+0000 to U+001F, which include tab, line feed and carriage return. Everything else, including accented letters and emoji, may appear as is.
Should I include the surrounding quotes?
No, in both directions. Escape mode outputs only the inside of the string, ready to drop between your own quotes. Unescape mode expects just the inside too, so pasting "hello" with its quotes gives the error Enter a valid JSON-escaped string (without the surrounding quotes).
Why does unescaping fail on a Windows path like C:\Users?
In JSON, a backslash always starts an escape sequence, and \U isn't a valid one. A JSON string holding that path must contain C:\\Users. Run the raw path through Escape mode to get the correct form.
Does the escaper convert é or emoji to \u sequences?
No. JSON allows any Unicode character inside a string, so é and emoji are left unchanged. Unescape mode does read \u escapes, so caf\u00e9 becomes café and the pair \ud83d\udc4d becomes a thumbs-up emoji.
Is my text uploaded?
No. Both directions run in your browser using its built-in JSON functions.