Skip to main content
CodeLint.Dev Dev Tools

JSON Escape & Unescape

Turn arbitrary text into a valid JSON string value, or reverse the backslashes in a double-encoded document to make it readable again.

Input

Paste your JSON here, or drag a file…

Drag & drop a file, or paste content above

Output

Output will appear here

The complete escape set

RFC 8259 defines exactly these. Everything else below U+0020 must use the \u form; everything at or above it may appear literally.

CharacterEscapeNotes
Double quote\"Required — an unescaped quote terminates the string
Backslash\\Required. The source of most double-encoding confusion
Forward slash\/Optional. Legal but never necessary; a hangover from embedding JSON in HTML script tags
Backspace\bU+0008
Form feed\fU+000C
Newline\nU+000A — required
Carriage return\rU+000D — required
Tab\tU+0009 — required
Any other control char\u00XXEverything below U+0020 must be escaped somehow
Any Unicode char\uXXXXAlways optional above U+001F — UTF-8 literals are valid and more readable

Note what is absent: there is no \x escape, no \0, no \v, and no \' — all are valid in JavaScript strings and invalid in JSON. Copying a JavaScript string literal into JSON is a reliable way to produce a parse error.

Double-encoding: why one field looks like this

You have almost certainly seen a log line or an API field that looks like this:

{"payload": "{\"user\":{\"name\":\"Alice\"}}"}

That is a JSON document whose payload field contains, as a string, another JSON document. Because the inner document contains double quotes, every one of them had to be escaped to survive inside the outer string. Nest a third level and the backslashes multiply again — \\\" — which is where readability disappears entirely.

This happens whenever a system that expects a string is handed structured data: message queues with string payloads, webhook fields typed as text, database columns declared VARCHAR, and logging libraries that serialise an already-serialised object.

To read one, unescape once per level of nesting. To produce one, escape once per level. The Unescape direction here does exactly that, and running it repeatedly peels the layers one at a time.

Whether double-encoding is a bug depends on the interface. If the field is genuinely typed as a string, it is correct and unavoidable. If the field could have been an object and someone stringified it anyway, it is a bug — it costs bytes, prevents querying the inner structure, and defers parse errors to a point far from where the data was produced.

Escaping in code

JavaScript
// Escape: stringify a string to get a quoted, escaped literal
JSON.stringify('He said "hi"\nthen left');
// -> "\"He said \\\"hi\\\"\\nthen left\""

// slice(1, -1) drops the surrounding quotes if you only
// want the escaped body
const escaped = JSON.stringify(text).slice(1, -1);

// Unescape: parse it back
JSON.parse('"line1\\nline2"');   // -> 'line1\nline2'
Python
import json

# Escape
json.dumps('He said "hi"\nthen left')

# Unescape one level
json.loads(escaped_string)

# Peel a double-encoded payload
outer = json.loads(raw)
inner = json.loads(outer["payload"])

About

The JSON Escape / Unescape tool handles the full set of escape sequences defined by the JSON specification: double quotes become \", backslashes become \\, newlines become \n, carriage returns become \r, horizontal tabs become \t, and non-printable Unicode control characters become \uXXXX sequences. This is essential when embedding arbitrary text inside a JSON string value — raw special characters break JSON parsers. The Unescape direction converts all of those sequences back to their literal characters, making double-encoded JSON readable again. Everything runs in your browser; nothing is transmitted to any server.

How to use

  1. 1 Paste your raw text (the content you want to embed as a JSON string value) into the input field.
  2. 2 The Escape mode is active by default — the escaped output appears immediately on the right.
  3. 3 Switch to Unescape mode to convert an already-escaped JSON string back to its literal form.
  4. 4 Copy the result with the Copy button and paste it directly into your JSON string value (between the quotes).
Why do I need to escape strings before putting them in JSON?
JSON string values cannot contain raw double quotes, backslashes, or control characters such as newlines and tabs. These must be written as escape sequences (\", \\, \n, \t). If you paste raw text containing these characters directly into a JSON string, the parser will fail with a syntax error. This tool handles the escaping for you in one click.
What exactly does this tool escape?
The tool escapes all characters required by the JSON specification: double quotes (→ \"), backslashes (→ \\), newlines (→ \n), carriage returns (→ \r), horizontal tabs (→ \t), and Unicode control characters in the range U+0000–U+001F (→ \uXXXX). Unescape reverses every one of these sequences back to its literal character.
When would I use JSON unescape?
Unescape is useful when you receive JSON that has been double-encoded — for example, a JSON payload stored as a string inside another JSON object, log output that printed the raw escaped representation of a JSON value, or a database column that contains a serialised JSON string. Running it through Unescape gives you the human-readable original text.
Does this tool wrap the result in quotes to make a complete JSON string?
No — the tool only escapes or unescapes the content of the string, not the surrounding quotes. You add the enclosing double quotes yourself when you paste the result into your JSON document. This keeps the tool flexible for any context.
Is my data sent anywhere?
No. Escaping and unescaping run entirely in your browser. Your text is never transmitted to any server, which makes it safe to use with log data, credentials, or any text that might contain sensitive information.