Escapar / Desescapar JSON

Paste it. Get the escaped string. Copy it into your JSON and move on.

Direction
0 characters

Any text works — an SQL query, a stack trace, a whole JSON document. It never has to be valid JSON.

0 characters

What gets escaped

Each character JSON requires an escape for, the sequence it becomes, and why.
CharacterBecomesWhy
"\"A bare quote would end the string early. This is the one that breaks payloads.
\\\A backslash starts an escape, so a literal one has to escape itself. Windows paths hit this constantly.
newline\nJSON strings can't span lines.
carriage return\rSame reason — and it travels with \n out of Windows files.
tab\tA raw tab inside a string is not allowed, however invisible it looks.
backspace\bU+0008. Rare in real text, legal in JSON.
form feed\fU+000C. Turns up in text extracted from PDFs.
other control characters\u00XXEverything below U+0020 that has no shorthand — a bell, a null, an escape character out of a terminal capture.

A forward slash is left alone. JSON allows \/ but has never required it — the habit comes from embedding JSON inside a <script> tag, where the sequence </ would end it early.

Pégalo. Obtén el string escapado. Cópialo en tu JSON y sigue con lo tuyo. Esa es toda la herramienta, y el resultado se actualiza mientras escribes, así que no hay botón que buscar. El trabajo que hace es concreto y muy común: tienes un bloque de texto —un mensaje de error, una consulta SQL, un documento JSON entero, una línea de log— y tiene que ir dentro del valor de un string JSON. Cada comilla doble tiene que convertirse en barra invertida más comilla, cada barra invertida tiene que duplicarse, cada salto de línea tiene que convertirse en un escape de dos caracteres y cada carácter de control invisible tiene que escribirse en hexadecimal. Hazlo a mano en un stack trace y te equivocarás en algún punto del medio, y luego pasarás veinte minutos leyendo un error del parser que señala un número de columna en vez de la comilla que se te escapó. El camino inverso es igual de común. Copias el valor de un string de un log, una respuesta de API o una fila de base de datos, y lo que obtienes es un muro de barra-n y barra-u que ahora tienes que leer. Esta página lo vuelve a convertir en texto. Es deliberadamente tolerante en esa dirección, porque lo que la gente pega de verdad es un valor que todavía tiene sus comillas exteriores, o un valor que ya trae un salto de línea real de donde lo copiaron, y las dos cosas hacen que la implementación obvia —pasarle el string a un parser JSON— lance un error que no le dice nada al usuario. Así que este desescapador lee el string carácter por carácter, quita un par de comillas exteriores si las hay y deja los saltos de línea reales, las tabulaciones reales y las comillas sueltas exactamente donde están. Solo se queja de lo único que de verdad no tiene respuesta: una barra invertida seguida de algo que no es una secuencia de escape. Cuando eso pasa, nombra la secuencia y la posición del carácter, para que vayas directo a ella. Todo funciona en el navegador. No hay subida, ni cuenta, ni límite de usos, y eso importa aquí más de lo que parece, porque los strings que la gente escapa suelen ser cadenas de conexión, tokens, registros de clientes o el contenido de una petición que falló, y nada de eso debería pegarse en el servidor de otro solo para añadir una barra invertida.

Built by Bob Article by Lace QA by Ben Shipped

Cómo usar

  1. 1

    Elige una dirección. Escapar viene seleccionado por defecto y convierte texto plano en un string JSON. Desescapar va al revés: convierte el cuerpo de un string JSON en texto legible.

  2. 2

    Pega tu texto. No tiene que ser JSON válido: una consulta SQL suelta, un stack trace, un comando de terminal o un documento entero funcionan igual. El resultado aparece debajo mientras escribes.

  3. 3

    Activa Envolver entre comillas si quieres un literal de string JSON completo. Déjalo apagado (por defecto) cuando vayas a pegar entre comillas que ya existen en tu archivo, que es el caso más común.

  4. 4

    Activa Escapar no-ASCII como \uXXXX si el JSON tiene que pasar por un sistema que no maneja bien UTF-8. Los acentos, el CJK y los emojis saldrán como escapes \u; los emojis se convierten en un par sustituto. Déjalo apagado para mantener el texto legible: los acentos sin escapar son JSON perfectamente válido.

  5. 5

    Copia el resultado. El botón copia toda la salida y muestra Copiado. para que sepas que funcionó.

  6. 6

    Usa Intercambiar para comprobar tu trabajo. Pasa la salida a la entrada e invierte la dirección, así que con un clic haces el viaje de ida y vuelta y ves cómo vuelve tu texto original sin cambios.

  7. 7

    Si estás desescapando y algo sale mal, lee el mensaje en vez de la salida. Nombra la secuencia de escape exacta que falló y la posición del carácter, que casi siempre es una sola barra invertida suelta que verás en cuanto sepas dónde mirar.

Preguntas frecuentes

Ratings & Reviews

Rate this tool

Sign in to leave a written review.
Loading reviews…

What does the JSON Escape / Unescape tool do?

It takes a piece of text and turns it into something you can drop between two quotes in a JSON file — and it reads one back out again. Paste He said "hi" and you get He said \"hi\" back, with the line underneath reading 12 characters in → 14 out, 2 escaped. That last number is the useful one: it tells you how much of your paste actually needed touching, and a zero tells you it was already safe to use as it stood.

Escape is the direction that's selected when the page loads, because it's why most people arrive. Switch to unescape and the same conversion runs backwards: paste \ud83d\ude00 and one 😀 comes out, a surrogate pair recombined into a single character. Neither direction requires your input to be valid JSON. A SQL query, a stack trace, a shell command, a whole JSON document, or one stray word with a quote in it all go through the same way. Far more people search for a JSON escape tool than a JSON unescape one, which is why the default sits where it does — but both halves of the job live on this one page.

The conversion runs in your browser, recomputing as you type on a 120 ms delay, so there's no Escape button to hunt for. Your text never leaves the machine. That matters more here than it does for most text tools, because the strings people need to escape a JSON string for are usually connection strings, bearer tokens, customer records, or the body of the request that just failed in production.

Which characters JSON makes you escape

The list is shorter than people expect, and it never changes — which means you can learn to escape JSON strings by eye and use the JSON Escape / Unescape tool for speed rather than for rescue. JSON requires an escape for exactly three groups of characters: the double quote, the backslash, and everything below U+0020. Five of those control characters have a one-letter shorthand; the rest are written as \u plus four hex digits.

CharacterBecomesWhere it usually comes from
"\"A quoted table name in SQL, an HTML attribute, a message that quotes someone.
\\\A Windows path, a regular expression, a LaTeX command, an escape you already applied.
newline\nAny multi-line paste at all — a stack trace, a query, an email body.
carriage return\rFiles written on Windows, HTTP headers, anything that travelled over a terminal.
tab\tPasted TSV, indented code, log lines with aligned columns.
backspace\bU+0008. Interactive terminal captures, occasionally a broken editor.
form feed\fU+000C. Page breaks in text extracted from a PDF.
anything else below U+0020\u00XXANSI colour codes from coloured console output, a stray null from a binary read.

Nothing else is required. Accents, CJK, emoji and the forward slash are all legal as themselves — JSON permits \/ but has never asked for it, so this tool leaves slashes alone.

If the summary says 0 escaped, your text contained none of the characters above and you can paste it between quotes untouched. That's a real answer, not a failure — plenty of pastes come back unchanged.

How the escaping works, character by character

The escape direction walks your text one UTF-16 code unit at a time. Quotes and backslashes get doubled up, the five named control characters get their shorthand, and any remaining character under U+0020 is written out in hex. Everything above that is copied through as itself, so café 😀 comes out as café 😀 — 7 characters in, 7 out, 0 escaped. That output is already valid JSON, and it stays readable in a diff.

Turn on Escape non-ASCII as \uXXXX and the same input becomes caf\u00e9 \ud83d\ude00: 7 characters in → 22 out, 3 escaped. Three, not two, because the emoji lives above U+FFFF and JSON writes such characters as the surrogate pair UTF-16 uses internally. Both forms parse to the identical string, so this is never a correctness question — only a question of whether the JSON has to survive a pipeline that isn't reliably UTF-8. One exception is not optional: half an emoji, a lone surrogate with no partner, is always escaped, because it has no valid encoding as itself.

The unescape direction is a hand-written scanner rather than a call to a JSON parser, and that choice is the point of the page. A parser rejects the two things people paste most often — a value copied with its outer quotes still attached, and a value carrying a raw newline from wherever it was copied — and it rejects them with a message that names a byte offset instead of the problem. So this scanner strips one matched pair of outer quotes if it finds them, keeps raw newlines, raw tabs and stray quotes as content, and reserves its errors for the three sequences that genuinely have no reading: an unknown escape, a truncated \u, and a backslash with nothing after it. Each one names the sequence and counts the position from the first character you can see.

Pages that do this job have a habit of growing into something else. The same four lines of string handling turn up as one tab inside a fifty-tool dashboard that wants an account before it will show you a backslash, or behind a fourteen-day trial, or bundled into a per-seat subscription somebody in procurement has to cancel. Escaping a quote is not a subscription business. This page escapes and unescapes, and that's the whole of it.

Worked examples in both directions

Every pair below is the exact output of the JSON Escape / Unescape tool, defaults on unless the row says otherwise.

What you pasteWhat comes outThe summary line
He said "hi"He said \"hi\"12 in → 14 out, 2 escaped
He said "hi" — Wrap in quotes on"He said \"hi\""12 in → 16 out, 2 escaped
C:\newC:\\new6 in → 7 out, 1 escaped
a, newline, tab, b, U+0007a\n\tb\u00075 in → 12 out, 3 escaped
\n (typed as two characters)\\n2 in → 3 out, 1 escaped
café 😀café 😀7 in → 7 out, 0 escaped

A longer one, the shape this actually comes up in. Take a two-line query with a quoted table name: SELECT * FROM "users", a real line break, then WHERE name = 'O''Brien';. Escaped, it becomes SELECT * FROM \"users\"\nWHERE name = 'O''Brien'; — 46 characters in → 49 out, 3 escaped. Two double quotes and the line break moved; the single quotes didn't, because JSON has no opinion about them.

Going the other way, three cases worth seeing. Paste "\"quoted\"" — a value copied straight out of a log, outer quotes included — and you get "quoted", with a note telling you one matched pair came off before reading and the inner pair was kept as content. Paste a\/b and you get a/b, since an escaped forward slash is legal even though nothing requires it. Paste \ud83d\ude00 and you get 😀: 12 characters in → 2 out, 2 escape sequences resolved.

The Swap button moves the output into the input box and flips the direction. One click sends a result back through the opposite conversion, and if your original text returns unchanged, the escape was right.

Where JSON escaping goes wrong

Almost every broken payload traces back to one of five things.

A Windows path that was never doubled. Unescape C:\Users\new and you get \U isn't a JSON escape sequence (character 3). Drop the backslash, or use \\ if you meant a literal one. The position counts from 1, through the string exactly as you pasted it, so you can count straight to the offending character. In the escape direction the same path needs no thought at all — each backslash simply doubles.

A payload escaped twice. If you see \\n in a value where you expected a line break, the string went through an escaper on its way into a field that then escaped the whole thing again. Nested API payloads do this constantly. Unescape JSON that arrived wrapped inside another field once, then look at what you have: if the result still reads as escapes rather than text, run it through again.

Assuming JSON takes the escapes your language does. It doesn't, and the JSON Escape / Unescape tool won't pretend otherwise. \x41, \0, \' and a backslash before a real line break are all fine in JavaScript or Python source and all illegal in JSON. Only eight letters follow a backslash in a JSON string, plus u and four hex digits.

Counting characters when something downstream counts bytes. café 😀 is 7 UTF-16 code units and 10 UTF-8 bytes. A varchar limit, a payload cap and a rate limiter usually mean bytes; the character counters in your editor usually mean code units. Escaping widens the gap, since every newline that becomes \n costs a byte more than it did.

Reading the output instead of the error. When the unescape direction fails it says which sequence broke and where. That message is almost always faster than re-reading the string, because a single stray backslash in a 4,000-character blob is invisible until something points at it.

Related developer tools

The JSON Escape / Unescape tool does one step of a longer job. Once your string is inside a document, the JSON formatter indents it and tells you whether the syntax parses, and the JSON diff shows what changed between two versions of a response. If the text is heading into a query string or an HTML attribute rather than a JSON string, the rules are different and so is the tool — use the URL encoder and decoder or the HTML encoder and decoder instead. For payloads that have to travel as plain ASCII regardless of content, the Base64 encoder and decoder is the blunter instrument. And when the shape of the data changes rather than its encoding, the JSON to YAML converter and the CSV to JSON converter handle those trips.

Frequently asked questions

Is JSON escaping the same thing as URL encoding or Base64?

No — three different jobs with three different rulebooks. JSON escaping protects a string from the JSON grammar, so quotes, backslashes and control characters get backslash sequences and nothing else moves. URL encoding protects a string from a URL, turning spaces into %20 and reserved characters into percent codes. Base64 re-encodes arbitrary bytes into 64 safe ASCII characters and makes the result unreadable but transport-proof. Applying the wrong one usually still produces valid-looking output, which is why the mistake tends to survive until something on the other end reads it back.

Do single quotes need to be escaped in a JSON string?

Never. JSON strings are delimited by double quotes only, so an apostrophe is an ordinary character and don't goes in exactly as it stands. If you're seeing doubled single quotes like O''Brien, that's SQL escaping its own string delimiter, and it should stay doubled — it's part of the query text you're embedding, not something JSON introduced. The confusion comes from JavaScript, where both quote characters delimit strings; JSON only inherited one of them.

Which number should I check against a database column — characters or bytes?

Usually bytes. The tool reports the input and output length in UTF-16 code units, which is what an editor's character count shows, and it measures its own 5 MB ceiling in UTF-8 bytes, which is what column limits, payload caps and rate limiters normally mean. The two diverge the moment you leave ASCII: an accented letter is one unit and two bytes, an emoji is two units and four bytes. If a value is close to a limit, assume bytes and give yourself room. The character counter is the tool for the other side of that question.

JavaScript and Python let me write \x41 and \0. Why does JSON reject them?

Because JSON's escape list is deliberately tiny: \", \\, \/, \b, \f, \n, \r, \t, and \u followed by four hex digits. That's all of it. There's no hex escape, no octal escape, no null shorthand, no line continuation. So a snippet of source code pasted into a JSON field will often carry escapes that look reasonable and parse nowhere. Escaping that snippet first is the fix: each backslash doubles, and the sequence survives as the literal text it was.

Does the case of an escape matter? Is \U0041 valid?

The u must be lowercase — \U0041 is not a JSON escape and the unescape direction says so, naming the position. The four hex digits after it can be either case, so \uD83D\uDE00 and \ud83d\ude00 both resolve to the same emoji. When this tool writes escapes itself it uses lowercase throughout, matching what every serialiser emits.

Can I escape a whole JSON document and put it inside another JSON string?

Yes, and it's a normal thing to do — webhook envelopes, message queues and audit logs all carry a JSON payload as a string field. Paste the document into the escape box and every quote and line break in it is handled; the result is one long line you can drop into the outer value. Remember that you'll need to unescape once to read it back, and that the character count grows sharply, because a document full of quotes is a document full of two-character escapes.

What happens to Windows line endings — do I lose the carriage return?

Nothing is lost. A CRLF pair becomes \r\n in the output, two escapes rather than one: a, CRLF, b is 4 characters in → 6 out, 2 escaped. Unescaping puts both characters back exactly as they were, so a round trip through the JSON Escape / Unescape tool preserves the line endings a file arrived with rather than quietly normalising them. Using the tool costs nothing and needs no account — and 10% of every dollar Microapp earns goes to charity, off the top, audited quarterly.