JSON Escape and Unescape Tool

A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call

Free JSON escape tool. Escape text for use inside a JSON string (quotes, backslashes, new lines, tabs, Unicode) or unescape a JSON string back to plain text.

Result

Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.

How to use the JSON escape tool

  1. Paste your text into the box: a message, an HTML snippet, a file path, a multi-line template, or anything else.
  2. Choose a mode:
    • Escape: turns the text into a safe JSON string body, without the surrounding quotes.
    • Escape and wrap in quotes: the same, with the double quotes added, ready to paste as a JSON value.
    • Unescape: turns an escaped JSON string back into plain text.
  3. Copy the result.

If the text can't be unescaped because it isn't a valid JSON string, the JSON escape tool explains what's wrong. Everything happens in your browser.

What JSON escaping is

JSON (JavaScript Object Notation) is the most common format for sending data between apps and APIs. In JSON, text values are strings wrapped in double quotes:

{"message": "Hello"}

Some characters can't appear directly inside a JSON string, because they'd break the format. A double quote would end the string early, and a raw line break isn't allowed at all. Escaping replaces these characters with escape sequences that start with a backslash.

The characters that are escaped

Character Escaped as
Double quote " \"
Backslash \ \\
New line \n
Carriage return \r
Tab \t
Backspace \b
Form feed \f
Other control characters (U+0000 to U+001F) \u followed by four hex digits

The JSON escape tool also escapes the Unicode line separator (U+2028) and paragraph separator (U+2029). These are valid inside JSON strings, but older JavaScript engines treated them as line breaks inside string literals, so escaping them makes the output safe to paste into JavaScript code too.

Forward slashes (/) don't need escaping in JSON, although some systems escape them as \/ when embedding JSON in HTML. Non-ASCII characters such as é, 日本 or emoji are valid in JSON as they are, so the tool leaves them readable.

An example

This text:

She said "hi"
C:\temp	ok

(with a line break after "hi" and a tab before "ok") becomes:

She said \"hi\"\nC:\\temp\tok

The quotes become \", the line break becomes \n, the backslash in the path becomes \\, and the tab becomes \t.

When you need to escape JSON

  • Writing JSON by hand for API requests, configuration files or test fixtures, when a value contains quotes or line breaks.
  • Putting HTML or code inside JSON, such as email templates or rich text stored in a database.
  • Windows file paths, where every backslash must be doubled.
  • Multi-line text in a JSON value, such as an address or a message.
  • Embedding a JSON document inside another JSON string, which happens with some logging tools and message queues.
  • Environment variables and command lines that take JSON values.

Unescaping JSON strings

The reverse is just as common. Logs, API responses and databases often show text with escape sequences, like Line one\nLine two, which is hard to read. Unescape mode turns it back into normal text with real line breaks. You can paste the string with or without its surrounding quotes.

If the input contains an invalid escape (such as \x, which JSON doesn't support), or an unescaped double quote in the middle, the JSON escape tool shows the parser's error message so you can find the problem.

Escaping in code

In most programming languages, the built-in JSON library escapes strings for you; you only need to escape by hand when you're writing JSON text directly.

  • JavaScript: JSON.stringify(text) returns the escaped string with quotes.
  • Python: json.dumps(text) does the same.
  • PHP: json_encode($text).

Building JSON by gluing strings together without escaping is a common source of bugs, and of security problems when user input is involved. Always use a proper JSON encoder in code.

Each format has its own escaping rules: JSON escaping isn't the same as HTML, URL or regex escaping, so use the right tool for where the text is going.

Common JSON escaping errors

When JSON fails to parse, these are the usual culprits:

  • An unescaped double quote inside a string, such as "She said "hi"". Put a backslash in front of it.
  • A real line break inside a string, often from copying multi-line text. Replace it with \n .
  • Single backslashes in Windows paths, such as C:\temp written with one backslash, where the backslash and t are read as a tab. Double every backslash in the path.
  • Single quotes around strings. JSON requires double quotes; single quotes are only valid inside a string.
  • Trailing commas after the last item in an object or array, which JSON doesn't allow.
  • Invisible control characters pasted from documents or terminals.

The JSON escape tool fixes the first three automatically, and the JSON formatter points to the line where a whole document breaks.

Escaping JSON for use in other places

Sometimes JSON has to go inside something else:

  • Inside an HTML attribute: escape the JSON for HTML too, turning " into ".
  • Inside a script tag: escape < as \u003c so a "" inside a string can't end the script early.
  • Inside a shell command: wrap the JSON in single quotes, and handle any single quotes inside it.
  • Inside another JSON string: escape it twice, once for each level. The JSON escape tool's "Escape and wrap in quotes" mode does one level at a time.

Each layer has its own rules, so escape for the innermost format first, then the outer one.

Unicode in JSON

JSON text is normally UTF-8, so characters like é, ü and emoji can appear directly in strings. They can also be written as \u escapes: é is \u00e9. Characters outside the Basic Multilingual Plane, such as most emoji, are written as two \u escapes, called a surrogate pair. Both forms mean exactly the same thing to a JSON parser; the JSON escape tool keeps characters readable where it's safe to do so.

Testing JSON after escaping

After escaping, check the result is valid by pasting a small test document into the JSON formatter, such as an object with your escaped string as a value. If it formats without errors, the escaping is correct.

JSON escape for configuration files

Many tools store settings as JSON, and values sometimes contain text with quotes, paths or line breaks, such as a custom message, a regular expression or a Windows folder. Escape the value first, then paste it between the quotes in the config file. Regular expressions need extra care: their own backslashes must be doubled in JSON, so a pattern like a backslash followed by d (meaning a digit) is written with two backslashes inside a JSON string. The JSON escape tool doubles them for you.

A worked example

A developer is writing a test fixture for an API that sends support messages. The message body contains a quote, a Windows path and a line break:

She said "hi"
C:\temp	ok

He pastes it into the JSON escape tool with "Escape and wrap in quotes" selected and gets:

"She said \"hi\"\nC:\\temp\tok"

He pastes it straight into his JSON file as the value of "body", and the file validates. Later, reading a log line that shows "Order shipped\nTracking: 1Z999", he switches to Unescape and sees the two lines as they were sent.

Need more customers from Google?

This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit is a Google Ads agency that does PPC and nothing else: we build the campaigns, block the searches that waste money, write the ads, set up conversion tracking and send you a short report every week. Request a free PPC audit and we will show you, in dollars, what we would fix first.

Frequently asked questions

How do I escape a string for JSON?

Replace double quotes with \", backslashes with \\, line breaks with \n and tabs with \t, and escape other control characters as \u codes. The JSON escape tool does all of this at once.

How do I put a new line in a JSON string?

Write it as \n inside the string. A real line break isn't allowed inside a JSON string.

Do forward slashes need escaping in JSON?

No. \/ is allowed but not required.

How do I unescape a JSON string?

Choose Unescape and paste the string, with or without quotes. The JSON escape tool turns escape sequences back into real characters.

Is JSON escaping the same as HTML escaping?

No. JSON uses backslash sequences; HTML uses entities like &quot;. Use the right one for where the text is going.

Is the JSON escape tool free?

Yes. It's free, needs no sign-up, and works in your browser.

Free PPC audit

See where your ad budget leaks.

We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.

Book a free audit call 30-minute call · Free · The audit is yours to keep