BYTETOOLS

How to Escape and Unescape Strings for JS and JSON

To escape a string for JavaScript or JSON, choose Escape mode, paste your text, and copy the result — the tool replaces quotes, backslashes, newlines and tabs with the backslash sequences a string literal needs. To reverse it, switch to Unescape mode. The ByteTools String Escape / Unescape tool does both directions in one place, and every conversion runs in your browser so your strings are never uploaded.

This tutorial covers each step, explains what the escaped forms mean, and shows when to turn on \uXXXX encoding.

What escaping actually does

A string literal in code is wrapped in quotes, so any character that would clash with those quotes — or break across a line — has to be written as a backslash sequence instead. A real line break becomes the two characters \n, a tab becomes \t, a double quote becomes \", and a backslash itself becomes \\. Escaping adds those sequences so text drops safely between quotes; unescaping strips them back out to recover the original readable text.

Step-by-step: escaping text

  1. Select Escape mode. This tells the tool to encode rather than decode.
  2. Paste your string. Drop in the raw text — a multi-line message, a path with backslashes, anything with quotes.
  3. Optionally tick 'Escape non-ASCII as \uXXXX'. Turn this on when the text must survive systems that only handle plain ASCII.
  4. Read the output. The converted literal appears below, ready to paste between quotes.
  5. Copy it into your code or JSON. One click and it is on your clipboard.

Step-by-step: unescaping text

Going the other way is just as quick. Switch to Unescape mode and paste an escaped value — perhaps a string pulled from a log file, a config, or a JSON payload. The tool decodes \n, \t and friends back into real characters, and it understands the three main Unicode forms: \uXXXX (four hex digits), \u{…} (variable length) and \xHH (two hex digits). The readable original appears below. If a sequence is malformed, you get a clear error naming the problem rather than silent corruption.

Common escape sequences at a glance

CharacterEscaped formMeaning
New line\nLine break
Tab\tHorizontal tab
Double quote\"Quote inside a string
Backslash\\Literal backslash
é (non-ASCII)\u00e9Unicode code point

When to use \uXXXX encoding

Leave non-ASCII escaping off for normal work — modern JSON and JavaScript handle UTF-8 accented characters and emoji directly, and the text stays readable. Turn it on when a string has to travel through older systems, email headers, or anything that mangles non-ASCII bytes: encoding é as \u00e9 keeps it portable. When you unescape later, those sequences decode straight back to the original characters.

Try the String Escape / Unescape — free and 100% in your browser.

FAQ

Do I need Escape or Unescape mode?

Use Escape when you have raw text and want a safe string literal to paste into code or JSON. Use Unescape when you already have an escaped value — with \n, \uXXXX and so on — and want the readable text back.

Will it break my JSON if I paste a whole object?

The tool escapes or unescapes the text you give it as a string value; it is not a JSON formatter. Paste the string content you want to encode, not the surrounding braces, and drop the result into your object as a value.

Why did unescaping throw an error?

A sequence is malformed — for example \u followed by fewer than four hex digits, or a string ending in a lone backslash. The message points at the offending sequence so you can fix it and run it again.

Is my text sent anywhere?

No. All escaping and unescaping happens locally in your browser with JavaScript, so nothing leaves your device — safe for tokens, config values and internal strings.

Related free tools

Built by ByteVancer

ByteTools is a free product of ByteVancer, a software and web development studio building web apps, SaaS and custom software. If developer tools like this speed up your day, see what ByteVancer can build for your product.