JSON Escape / Unescape Online

Escape JSON into a safe string for code, APIs and config values, or unescape a JSON string back to normal JSON.

Text Input

Ln 1, Col 1Empty

Result

Your result will appear here.
No result yet

What Is JSON Escaping?

Escaping JSON means turning it into one safe text string. Every double quote becomes \", every line break becomes \n, and every backslash becomes \\. You need escaped JSON when you store JSON inside another JSON value, put it in a code string, send it in an API field or save it in an environment variable.

How to Escape or Unescape JSON

  1. Paste your JSON or text into the Text Input box.
  2. Click Escape to turn it into a string, or Unescape to turn a string back into JSON.
  3. Click Copy or Download to save the result.

Example

This JSON:

{"message": "She said \"Hi\""}

escaped becomes:

"{\"message\": \"She said \\\"Hi\\\"\"}"

Features

  • Escapes quotes, backslashes, tabs, line breaks and other control characters.
  • Unescapes strings with or without the outer quotes.
  • Formats the result automatically when the unescaped text is JSON.
  • Runs in your browser. Nothing is uploaded.

When You Need Escaped JSON

  • JSON inside JSON: some APIs and message queues expect a field whose value is a JSON string, for example a payload or metadata field.
  • Code: putting a JSON example inside a JavaScript, Java or C# string.
  • Environment variables and CLI arguments: passing a JSON config on one line.
  • Databases and logs: some systems store JSON as escaped text in a single column or log line.

Escape and Unescape in Code

JavaScript
const obj = { user: 'Emily', note: 'Line 1\nLine 2' }

const escaped = JSON.stringify(JSON.stringify(obj))
// "{\"user\":\"Emily\",\"note\":\"Line 1\\nLine 2\"}"

const back = JSON.parse(JSON.parse(escaped))   // the original object
Python
import json
escaped = json.dumps(json.dumps(obj))
back = json.loads(json.loads(escaped))

Calling JSON.stringify twice is the trick: the first call turns the object into JSON text, the second turns that text into a string with every quote and backslash escaped.

Common Mistakes

  • Double escaping: if you see \\\" in your data, the JSON was escaped twice. Unescape it once more, or let the JSON Parser unwrap every layer at once.
  • Escaping by hand: replacing quotes yourself easily misses backslashes, tabs or line breaks. Let a tool or JSON.stringify do it.
  • Using it for HTML or URLs: JSON escaping does not make text safe for HTML pages or links. For links, use URL Encode.

Frequently Asked Questions

What does it mean to escape JSON?

Escaping turns JSON into a single text string: quotes become \", line breaks become \n and backslashes are doubled. You need this when you put JSON inside another JSON value, a code string or an environment variable.

How do I unescape a JSON string?

Paste the escaped text (with or without the outer quotes) and click Unescape. If the result is JSON, it is formatted for you.

Is this tool free?

Yes. It is free to use and needs no sign-up.

Is my data private?

Yes. The escaping and unescaping happen in your browser. Nothing is uploaded.

Related Tools