JSON Escape / Unescape

Escape raw text into a safe JSON string, or unescape a JSON string back into readable text. Paste or upload, and copy or download the result — all in your browser.

100% Client-Side Processing

Your text is processed entirely in your browser. Nothing is uploaded to a server.

Turn raw text into a JSON-safe string: quotes, backslashes, newlines, tabs, and control characters are escaped so the result can be dropped straight into a JSON document.

Escaped output
Lines: 0 Characters: 0

What is JSON Escape / Unescape?

JSON escaping is the process of rewriting text so it can safely be used as the value of a JSON string. Characters like double quotes, backslashes, and newlines have special meaning inside a JSON string and must be replaced with backslash-prefixed escape sequences (\", \\, \n, and so on) — otherwise the JSON becomes invalid or gets parsed incorrectly.

Unescaping is the reverse: taking a JSON string that already contains escape sequences — often copied from an API response, a log file, or source code — and decoding it back into the plain, readable text it represents. This tool does both directions instantly in your browser.

How it Works

  • Choose a direction: Escape (raw text → JSON-safe string) or Unescape (JSON string → raw text).
  • Add your text: Paste it directly, or upload a .txt or .json file.
  • Set your options (Escape mode only): choose whether to wrap the result in double quotes, and whether forward slashes should be escaped as \/.
  • Read the result instantly: The tool converts your text in your browser as you type, along with line and character counts.
  • Copy or download: Copy the result to your clipboard or download it as a file.

Features

  • Escape raw text into a JSON-safe string, or unescape a JSON string back into text
  • Instant, live conversion as you type — no button to click
  • Optional wrapping of escaped output in double quotes
  • Optional escaping of forward slashes (useful when embedding JSON inside a <script> tag)
  • Unescaping accepts input with or without surrounding double quotes
  • Correctly decodes \uXXXX Unicode escapes, including surrogate pairs for emoji and other characters outside the Basic Multilingual Plane
  • Clear error messages for a trailing backslash, an invalid escape sequence, or a malformed \u escape
  • Paste text or upload a .txt/.json file
  • Live line and character counts
  • 100% client-side processing for privacy

Best Practices

  • Turn off "Wrap output in double quotes" when embedding into existing JSON: if you're pasting the escaped result into a JSON document you're editing by hand, you usually already have the surrounding quotes in place and only need the escaped inner content.
  • Turn on "Escape forward slashes" for JSON embedded in HTML: a literal "</script>" sequence inside a JSON string embedded in an HTML <script> tag can prematurely close the tag — escaping slashes as \/ avoids this class of bug.
  • Unescape works with or without quotes: paste a full quoted string value copied from an API response, or just the inner escaped text — both are handled the same way.
  • Double-check the source before unescaping: this tool decodes backslash escape sequences character by character; it does not validate that the surrounding content is otherwise valid JSON.
  • Watch for double-escaping: if your text already has doubled backslashes (\\\\n instead of \n), it may have been escaped twice — run it through Unescape mode twice, or check the source that produced it.

Troubleshooting

Unescape says my string ends with a lone backslash

A backslash at the very end of the string with nothing after it isn't a valid escape sequence in JSON. Check whether a backslash was accidentally left dangling, or whether the string was truncated when it was copied.

Unescape says there's an invalid escape sequence

JSON only recognizes \", \\, \/, \n, \r, \t, \b, \f, and \uXXXX as valid escapes. A backslash followed by anything else (like \x or \e) isn't valid JSON and will be flagged.

Unescape says a \u escape is invalid

A \u escape must always be followed by exactly 4 hexadecimal digits (0-9, a-f, A-F), like \u00e9. If it's followed by fewer characters, non-hex characters, or nothing, it can't be decoded.

My emoji or special character didn't come through correctly

Characters outside the Basic Multilingual Plane (like most emoji) are represented in JSON as a surrogate pair — two consecutive \uXXXX escapes. Make sure both halves of the pair are present and in order; a single half on its own can't be decoded correctly.

Common Use Cases

  • Embedding user-generated or file content into a JSON payload: safely escape a block of code, a multi-line comment, or arbitrary text before inserting it as a JSON string value.
  • Reading escaped strings from logs or API responses: unescape a JSON string value you copied from a log line or debugger to read the actual text it represents.
  • Preparing JSON for embedding in HTML: escape forward slashes so a JSON string embedded inside a <script> tag can't be broken by a literal </script> sequence.
  • Debugging JSON parsing errors: unescape a suspicious string to see exactly what characters it contains, including invisible ones like tabs and newlines.
  • Writing JSON by hand: escape a snippet of source code, a file path, or another string before manually typing it into a JSON file or API request body.

Frequently Asked Questions

What's the difference between escaping and encoding?

Escaping specifically deals with characters that have special meaning inside a JSON string (quotes, backslashes, control characters) and replaces them with backslash sequences. It's a much narrower operation than general text encoding — it doesn't change the character set or compress the text.

Do I need the surrounding quotes when I unescape?

No. This tool detects a single pair of wrapping double quotes and strips them automatically if present, but also works correctly if you paste just the inner escaped text without quotes.

Why isn't a forward slash escaped by default?

JSON does not require forward slashes to be escaped — "/" and "\/" are both valid and decode to the same character. It's left off by default to keep the output cleaner, with an option to turn it on for contexts (like JSON embedded in a <script> tag) where escaping slashes avoids a specific bug.

Does escaping change non-ASCII characters like accented letters or emoji?

No. This tool leaves ordinary Unicode characters (accented letters, non-Latin scripts, emoji) untouched in the output — JSON strings can contain any Unicode character directly, so escaping them to \uXXXX sequences isn't necessary. Only quotes, backslashes, and control characters are escaped.

Can I paste the whole JSON document instead of just a string value?

This tool is built for escaping/unescaping a single text value, not for parsing a full JSON document. Escaping an entire document will treat it as one long string rather than converting the strings inside it — use it on individual string values instead.

Do you store my text?

No. Everything happens locally in your browser, and nothing is uploaded or saved.

Is there a size limit?

The tool runs in your browser's memory, so very large files (tens of megabytes or more) may be slow or use a lot of memory depending on your device.

Share this tool

Share a direct link or embed this tool on your site. Keep the Tooladex attribution link to support the project.