We use cookies

We use cookies and similar technologies to enhance your browsing experience, analyze site traffic, and personalize content and ads. By clicking "Accept", you consent to our use of cookies. Learn more in our Privacy Policy.

Free · in your browser · no signup

String Escaper / Unescaper

Escape text into a safe JSON string body (quotes, newlines, tabs, backslashes) or unescape it back to plain text — instantly.

The String Escaper / Unescaper turns ordinary text into a valid JSON string body and back again. Paste a code snippet, a multi-line log, or a sentence with quotes, and it converts the characters that would break a JSON string — double quotes, backslashes, newlines, tabs, carriage returns — into their escaped forms (", \, \n, \t, \r). The unescape direction does the reverse, decoding an escaped string back to its literal text so you can read it normally.

It's built for the moment you need to drop a chunk of text into a JSON field, a config file, a string constant, or an API request and don't want to hand-escape every quote and line break. Everything runs in your browser; the text you paste never leaves your device, which matters when the snippet is a private key, an internal log line, or anything you'd rather not send to a server.

What it does and how it works

The tool has two modes:

  • Escape — takes raw text and produces the characters you'd put inside a pair of JSON double quotes. It replaces each control or reserved character with its two-character escape: " becomes \", \ becomes \\, a newline becomes \n, a tab becomes \t, and a carriage return becomes \r.
  • Unescape — reads an already-escaped string and rebuilds the original, turning \n back into a real line break, \" back into ", and so on.

It does not add the surrounding quotes for you — it produces the body of the string, so you can paste it straight between your own quotes wherever you need it. Processing happens entirely client-side: nothing is uploaded, and the result updates as you type.

A worked example

Say you have this two-line message with a quoted word:

She said "hi".
Then left.

Escaping it gives you a single safe line:

She said \"hi\".\nThen left.

Drop that between quotes and it's a valid JSON value:

{ "message": "She said \"hi\".\nThen left." }

Run the same escaped text through Unescape and you get the original two lines back, quotes and line break restored. The backslash is the part people forget: a Windows path like C:\Users\me has to become C:\\Users\\me, otherwise \U and \m are read as (invalid) escape sequences and the JSON fails to parse.

Common use cases

  • Embedding text in JSON — putting a log line, error message, or paragraph into an API payload or a .json config without breaking it.
  • Building string constants — generating the escaped body for a string literal in JavaScript, Python, or another language that shares JSON's escape rules.
  • Reading escaped data — you copied a value out of a JSON file or an API response and want to see the real newlines and quotes instead of \n and \".
  • Pasting code into a JSON field — fitting a multi-line SQL query, shell command, or HTML snippet into a single JSON string.
  • Cleaning up logs — turning a \n-littered log string back into readable, line-broken text for debugging.

Tips and gotchas

  • Escape order matters. Backslashes must be escaped first; otherwise the backslashes you add for \n or \" get double-escaped. The tool handles this for you, but it's the most common mistake when people do it by hand.
  • You get the body, not the quotes. Add your own surrounding " — pasting the output already wrapped in quotes will double them up.
  • Single quotes don't need escaping in JSON. Only the double quote does. A ' passes through unchanged.
  • Round-tripping should be lossless. Escape then unescape (or the reverse) returns the original text. If it doesn't, the input wasn't valid for the direction you chose — for example, a lone trailing \ in unescape mode has nothing to pair with.
  • Watch invisible characters. A trailing tab or a stray carriage return becomes a visible \t or \r after escaping, which is a useful way to spot whitespace you didn't know was there.

Why JSON strings need escaping at all

A JSON string is delimited by double quotes, so the parser needs an unambiguous way to tell a quote that ends the string from a quote that's part of the string. That's what the backslash escape does: \" means "a literal quote, keep going." The same logic covers the backslash itself (\\) and characters that can't appear literally inside a string at all — newlines, tabs, and other control characters below code point U+0020.

Those control characters are forbidden raw: a real line break inside a JSON string is a parse error, which is why a newline must be written as the two characters \n. JSON also allows a \uXXXX form for any Unicode character, but for everyday text the short escapes (\n, \t, \r, \", \\) are all you need, and they're exactly what this tool produces. Most C-style languages — JavaScript, Java, C#, Python — use the same set, so escaped JSON bodies usually drop straight into their string literals too.

Tips

  • Escape backslashes before anything else, or your added escapes get mangled — the tool does this in the right order automatically.
  • The output is the string body only; wrap it in your own double quotes when you paste it.
  • Windows paths are a classic trap: C:\Users must become C:\\Users to survive JSON parsing.
  • Escape then unescape to sanity-check: you should get your exact original text back.
  • Use escape mode to reveal hidden whitespace — stray tabs and carriage returns show up as visible \t and \r.
  • Single quotes and forward slashes don't need escaping in JSON, so they pass through untouched.

How to use String Escaper / Unescaper

  1. 1Paste the text you want to escape or unescape.
  2. 2Click Escape to convert special characters into their backslash escapes.
  3. 3Click Unescape to turn escape sequences back into real characters.
  4. 4Copy the result — all done locally in your browser.

Frequently asked questions

What's the difference between escaping and unescaping?

Escaping converts raw text into a form that's safe to place inside a JSON string (real newlines become \n, quotes become \"). Unescaping does the reverse, turning \n back into an actual line break and \" back into a quote so the text is readable again.

Does it add the surrounding double quotes?

No. It produces the body of the string — the part that goes between the quotes — so you can paste it into whatever field or literal you're building. Add the quotes yourself.

Which characters get escaped?

Double quote (\"), backslash (\\), newline (\n), carriage return (\r), and tab (\t). These are the characters that would otherwise break a JSON string.

Why do I need to escape backslashes?

Inside a JSON string, a backslash starts an escape sequence, so a literal backslash has to be written as two: \\. Skip this and paths like C:\new get misread, because \n is interpreted as a newline.

Can I use the output in JavaScript or Python, not just JSON?

Usually yes. JavaScript, Python, Java, and C# all share JSON's core escape sequences (\n, \t, \", \\), so an escaped JSON body normally drops straight into a string literal in those languages.

Is my text uploaded anywhere?

No. Escaping and unescaping run entirely in your browser. Nothing is sent to a server, so it's safe for private logs, keys, or internal snippets.

Why does a newline turn into \n instead of staying a line break?

A raw line break inside a JSON string is a parse error. JSON requires control characters like newlines and tabs to be written as escape sequences, so a newline becomes the two characters \n.

I unescaped something and got weird results — what happened?

Unescape mode expects valid escape sequences. A lone backslash with nothing valid after it, or an incomplete \u sequence, has no clean counterpart and won't round-trip. Check that the input is actually escaped text, not raw text.

← All toolsRead our guides →