JSON Escape / Unescape

Escape any text into a JSON string literal — or back again.

Runs in your browser Instant No sign-up
Mode
Input
Result

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use JSON Escape / Unescape

  1. Mode: Escape turns raw text into a JSON string literal; Unescape does the reverse.
  2. Paste your text. The result updates as you type.
  3. When escaping, turn off Wrap in quotes if you only need the inner content, for example to paste between quotes you already have. Turn on Escape non-ASCII for ASCII-only output.
  4. Copy the result.

Example

This SQL, with a real line break and a tab:

SELECT * FROM "users"
WHERE name = 'Linh'	AND city = "Hà Nội" -- C:\temp

escapes to:

"SELECT * FROM \"users\"\nWHERE name = 'Linh'\tAND city = \"Hà Nội\" -- C:\\temp"

Single quotes don’t need escaping in JSON, and Hà Nội stays readable. With Escape non-ASCII on, it becomes H\u00e0 N\u1ed9i.

When you need this

  • Embedding text in a JSON payload: an SQL query, HTML snippet, Markdown document or stack trace as the value of a field in an API request or config file.
  • LLM and API requests: putting a multi-line prompt or code sample in the content field of a request body.
  • Environment variables and CI secrets: storing a JSON document or a PEM key that contains newlines as a single-line value.
  • Reading logs: log lines often contain escaped payloads like {\"id\":1}. Unescape them to get the original text back, then format it with the JSON Formatter.

Common mistakes

  • Double escaping. If the output shows \\n where you expected \n, the text was escaped twice — usually a value that was already a JSON string got escaped again. Switch to Unescape, run it once, and check the result.
  • Pasting a whole document into Unescape. Unescape expects one string literal. An object such as {"a":1} is rejected with a hint to use the JSON Formatter, which is the right tool for documents.
  • Using the wrong kind of escaping. JSON escaping is not URL encoding, HTML escaping or Base64. Use URL encoding for query strings and Base64 for binary data or values that must survive any transport unchanged.

Escape sequences reference

Character Escaped as
" \"
\ \\
newline, carriage return, tab \n, \r, \t
backspace, form feed \b, \f
other control characters (U+0000–U+001F) \u0000 to \u001f
non-ASCII, with the option on \u00e0, \ud83d\ude00

Doing it in code

// JavaScript
const escaped = JSON.stringify(text);   // includes the quotes
const original = JSON.parse(escaped);   // unescape
# Python — ensure_ascii=False keeps accents readable
import json
escaped = json.dumps(text, ensure_ascii=False)
original = json.loads(escaped)
# jq: raw text file → one JSON string
jq -Rs . < input.txt

Have a whole broken JSON document rather than one string? Try JSON Repair.

Frequently asked questions

Which characters get escaped?

Double quotes become \", backslashes become \\, and newline, tab, carriage return, backspace and form feed become \n, \t, \r, \b and \f. Other control characters below U+0020 become \u00XX. Everything else, including accented letters and emoji, is left as-is unless "Escape non-ASCII" is on.

What does "Escape non-ASCII" do?

It replaces every character from U+007F upward with a \uXXXX escape, so the output is pure ASCII. Characters outside the Basic Multilingual Plane, such as emoji, become a surrogate pair: 😀 becomes \ud83d\ude00. Use it when the receiving system mangles UTF-8.

Do I need to include the surrounding quotes when unescaping?

No. Both "line1\nline2" and line1\nline2 work. The input must be a single JSON string, though; if you paste an object or array, the tool tells you to use the JSON Formatter instead.

Why does unescape report an invalid escape sequence?

JSON only allows \" \\ \/ \b \f \n \r \t and \uXXXX. Escapes from other languages, such as \x41, \' or \0, are rejected, and the error shows the exact column.

Is my text uploaded?

No. Escaping runs in your browser using its built-in JSON.stringify, so the output matches what JavaScript produces. Nothing is uploaded.

Last updated