GALAXY OF TOOLS

DEV SECTOR

JSON Escape / Unescape

Escape text for JSON, JavaScript, Java, C#, Python, SQL, regex, shell or CSV, unescape it back, or parse nested JSON.

Runs entirely in your browser. Nothing you enter or upload is sent to a server.

JSON escape and unescape without guesswork

The JSON Escape / Unescape tool turns any text into a valid JSON string literal and decodes escaped strings back into readable text. Paste a multi-line message, a Windows path or a snippet of HTML and you get a string with every quote, backslash and control character escaped correctly — ready to drop into a JSON file, an API request body or a test fixture.

It also handles JSON inside JSON. Stringify JSON encodes a whole document as one string, the double-encoded form you meet in log lines, message queues and database columns. Parse JSON string reverses it, unwrapping as many levels as it finds and formatting the result. When an escape is broken, you get the exact line and column instead of a vague “unexpected token”.

All conversion happens in your browser, so secrets in payloads and logs stay on your device.

How to use the JSON Escape / Unescape

  1. Choose a mode: Escape text, Unescape string, Stringify JSON or Parse JSON string. Each mode loads a short sample you can replace.
  2. Paste into the left box, drop a file on it or press Load file. The result appears on the right as you type.
  3. For escaping, decide how to treat non-ASCII characters and whether you want surrounding quotes, \/ or HTML-safe output.
  4. For unescaping, read any error message — it gives the line, column and the faulty escape — and fix the input, or tick Accept raw line breaks, tabs and quotes for sloppy input.
  5. Press Copy result, or Use result as input to reverse the conversion and check the round trip.

JSON Escape / Unescape features

Matches JSON.stringify

With default settings the output is exactly what JavaScript’s JSON.stringify produces: short escapes for \b \f \n \r \t, \u00XX for other control characters and UTF-8 for everything else.

ASCII-only output

Escape every non-ASCII character as \uXXXX, or only emoji and characters outside the Basic Multilingual Plane, which JSON writes as a UTF-16 surrogate pair such as \ud83d\ude00.

Safe for HTML

The HTML-safe option escapes <, >, &, U+2028 and U+2029, so JSON can sit inside a <script> tag without closing it early.

Precise error positions

Invalid escapes like \q or \x41, incomplete \u sequences, raw line breaks and unpaired surrogates are reported with their line and column.

Several levels at once

Parse JSON string keeps unwrapping while the result is still a JSON string, then formats the document with 2 spaces, 4 spaces or tabs.

Numbers untouched

Stringify and parse work on the text itself, so large IDs such as 12345678901234567890 keep every digit.

JSON escape sequences

RFC 8259 requires three things to be escaped inside a string — the double quote, the backslash and control characters U+0000 to U+001F — and allows a few optional ones:

CharacterEscapeRequired?
Double quote "\"Yes
Backslash \\\Yes
Line feed, carriage return, tab\n, \r, \tYes
Backspace, form feed\b, \fYes
Other control characters\u0000 – \u001fYes
Forward slash /\/No — optional
Any other character\uXXXX (a surrogate pair above U+FFFF)No — optional

Worked examples

  • Escaping the two-line text She said "hi" + line break + C:\temp gives "She said \"hi\"\nC:\\temp".
  • With Escape all as \uXXXX, café 😀 becomes "caf\u00e9 \ud83d\ude00" — the emoji takes two escapes because it lies outside the Basic Multilingual Plane.
  • Stringifying {"a": [1, "x"]} with “Minify the JSON first” gives "{\"a\":[1,\"x\"]}"; parsing that string returns the formatted document.
  • Unescaping "abc\qdef" stops at line 1, column 5: \q is not a JSON escape.

String escape for other languages

Pick a language in Escape text or Unescape string; “Use result as input” checks the round trip.

LanguageHow text is escaped
JavaScript / TypeScriptBackslash escapes, \xHH for control characters, double or single quotes; unescaping also reads \u{1F600}.
Java\n \t \" \\ and octal \007 for other control characters — a \u000a in Java source would end the line.
C#\0 \a \b \f \n \r \t \v plus \uXXXX; unescaping reads \x and \U.
Python\xHH, \uXXXX and \U0001F600 for emoji when you choose ASCII output.
SQLSingle quotes doubled: 'O''Brien'. MySQL also treats backslash as an escape by default.
RegexMetacharacters such as . * + ? ( ) [ ] get a backslash, so the text matches literally.
ShellSingle-quoted, with '\'' for each quote; or backslash escapes when quotes are off.
CSVQuoted when needed, with quotes doubled (RFC 4180).

Common causes of broken escapes

  • Windows paths pasted as-is: C:\new\table silently turns into a line break and a tab. Each backslash must be doubled.
  • Escapes from other languages: \x41, \' and \0 are valid in JavaScript or Python strings but not in JSON.
  • Strings cut in half, which leaves a high surrogate such as \ud83d without its partner and produces a � replacement character.
  • Copying from a log line that already shows escaped text, so the string is decoded one level too few — use Parse JSON string to unwrap every level.

JSON Escape / Unescape FAQ

How do I escape a string for JSON?

Choose Escape text and paste the text. The JSON escape result is a quoted string literal with quotes, backslashes and control characters escaped — copy it into your JSON as a value.

How do I remove backslashes from escaped JSON?

Use Parse JSON string if the text is a JSON document stored as a string, or Unescape string for ordinary text. Both decode \" to " and \\ to \.

Do I need to escape non-ASCII characters?

No. JSON is UTF-8 and any Unicode character may appear unescaped. Escaping to \uXXXX is useful only when a system or file format cannot handle anything but ASCII.

Why do emoji become two \u escapes?

A \u escape holds four hexadecimal digits, enough for U+0000 to U+FFFF. Characters above that, such as most emoji, are written as two escapes — a high and a low surrogate — exactly as in UTF-16.

What is double-encoded JSON?

It is a JSON document that was turned into a string and then embedded in more JSON, so quotes appear as \". It often comes from logging an object that was already serialised. Parse JSON string undoes any number of levels; the JSON Formatter can then validate or minify it.

How do I escape a single quote in SQL?

Choose SQL and paste the text: each single quote is doubled, so O'Brien becomes 'O''Brien'. Prefer parameterised queries in real code.

Is this the same as URL or HTML encoding?

No. Each format has its own rules. Use the URL Encoder for query strings and the HTML Entity Encoder for text inside HTML.

You might also need