UtilityKit

500+ fast, free tools. Most run in your browser only; Image & PDF tools upload files to the backend when you run them.

JSON Escape / Unescape

Escape plain text for JSON or decode escaped text

About JSON Escape / Unescape

JSON Escape / Unescape on UtilityKit converts plain text into a valid JSON string value and reverses the process — entirely in your browser with no server involvement. When embedding arbitrary text inside a JSON string, double quotes must become \", newlines must become \n, tabs must become \t, and backslashes must become \\ — otherwise the parser throws a syntax error. This tool handles every sequence in the JSON spec: \" \\ \n \r \t \b \f and \uXXXX for control characters below U+001F. The Escape button wraps JSON.stringify, so output is spec-correct. Unescape reverses via JSON.parse. Common uses: embedding multiline log output in an API payload, fixing Unexpected token errors from unescaped quotes, storing SQL or HTML in a JSON field, and decoding escaped strings from webhooks.

Why use JSON Escape / Unescape

Spec-Correct Escaping via JSON.stringify

The Escape operation wraps native JSON.stringify, guaranteeing every required escape sequence (\n, \t, \", \\, \uXXXX) is handled exactly as the JSON RFC requires — no hand-rolling escape logic.

Fix 'Unexpected Token' Errors Instantly

Paste the offending string, click Escape, and copy the corrected value back into your JSON payload to resolve parser errors caused by unescaped quotes or control characters in seconds.

Handle Multiline Text and Code Blocks

Log output, SQL queries, and code snippets often contain newlines and tabs. The tool escapes them to \n and \t so the entire block fits legally inside a single JSON string value.

Unescape Received Payloads for Readability

Webhook payloads, API responses, and log lines often contain JSON strings with embedded escaped content. Paste and Unescape to read the original text without manually replacing every \n.

Purely Browser-Side — Safe for Secrets

Escaping and unescaping happen entirely in your browser via native JavaScript. No text is sent to a server, making it safe to use with log lines that may contain credentials or PII.

Handles Unicode Control Characters

Characters below U+001F — which are invisible and illegal in raw JSON strings — are automatically escaped to their \uXXXX representation, preventing silent parser failures.

How to use JSON Escape / Unescape

  1. Paste the raw text you want to embed inside a JSON string into the Input field.
  2. Click 'Escape for JSON' — the tool wraps the text in JSON.stringify logic and outputs the safely escaped string (without the surrounding double quotes) ready to paste between JSON string delimiters.
  3. Copy the escaped output and paste it as the value inside your JSON payload (e.g. { "message": "<paste here>" }).
  4. To reverse the process, paste an already-escaped JSON string value into the Input field.
  5. Click 'Unescape JSON string' — the tool decodes all escape sequences and outputs the original plain text.
  6. Review the output for any remaining escape sequences; if the text was double-escaped, run Unescape a second time.

When to use JSON Escape / Unescape

  • When you need to embed a multiline error message, stack trace, or log entry as a string value inside a JSON request body or config file.
  • When a JSON parser returns 'Unexpected token' or 'Bad control character' and you suspect an unescaped quote, newline, or backslash in a hardcoded string value.
  • When preparing a SQL query or HTML fragment to store in a JSON field in a database and the content contains double quotes or backslashes.
  • When receiving an escaped JSON string from an API or webhook and you want to read the original text without manually scanning for \n and \t sequences.
  • When writing test fixtures or mocking API responses where string values must be valid JSON but the content was originally formatted as free text.
  • When double-escaped strings from a pipeline (e.g. a string that was JSON-stringified twice) need to be unwound step by step to find the root value.

Examples

Embed a multiline error message in a JSON payload

Input: TypeError: Cannot read properties of undefined at app.js:42 at index.js:18

Output: TypeError: Cannot read properties of undefined\n at app.js:42\n at index.js:18

Escape a string containing double quotes

Input: He said "Hello, World!" and left.

Output: He said \"Hello, World!\" and left.

Unescape a received webhook string value

Input: Line 1\nLine 2\tTabbed\nLine 3

Output: Line 1 Line 2 Tabbed Line 3 (rendered with actual newlines and tab)

Tips

  • Always use the Escape output as the value between existing double quotes in your JSON — do not add extra quotes around it; the tool intentionally strips the outer quotes that JSON.stringify would normally include.
  • If you paste a full JSON string including the surrounding " characters into the Unescape field, remove the outer quotes first — the tool expects the inner escaped content only.
  • For double-escaped strings (common when JSON is serialized inside another JSON string), run Unescape twice: the first pass removes the outer escaping, the second restores the original text.
  • Backslashes in Windows file paths (e.g. C:\Users\name) are the most common cause of JSON parse errors in config files — paste the path and click Escape to get the correct C:\\Users\\name form.
  • When writing Jest or Vitest fixtures with inline JSON, use Escape to prepare any string literal that spans multiple lines or contains quotes, then paste it into the test file as a safe one-liner.

Frequently Asked Questions

Why do I need to escape text before putting it in JSON?
JSON uses double quotes to delimit strings. If your text contains double quotes, backslashes, newlines, or certain control characters, they must be escaped with a preceding backslash — otherwise the JSON parser cannot tell where the string ends and throws a syntax error.
What escape sequences does the tool produce?
It produces all sequences required by the JSON spec: \" for double quotes, \\ for backslashes, \n for newlines, \r for carriage returns, \t for tabs, \b for backspaces, \f for form feeds, and \uXXXX for control characters below U+001F.
Does this tool format or validate a full JSON object?
No. This tool operates on a single string value — it escapes or unescapes the content that would go between the JSON quote delimiters. To format or validate a complete JSON document, use the JSON Formatter tool.
The output still has \n in it after unescaping — why?
The input may be double-escaped (each \n was stored as \\n). Run Unescape a second time on the output to unwrap the second layer of escaping.
Can I use this to escape HTML inside a JSON string?
The tool escapes characters that are special in JSON, not HTML. If you need to embed HTML safely in JSON, first escape the JSON-special characters with this tool, then the resulting string is valid JSON. HTML entity encoding (& → &) is a separate step if the receiving end requires it.
Is the output safe to paste directly into a JSON string value?
Yes. The Escape output contains no unescaped double quotes, backslashes, or control characters, so you can paste it verbatim as the value between the surrounding double quotes in your JSON document.
Does it handle Unicode characters outside ASCII?
Yes. Standard Unicode letters and symbols pass through unchanged. Characters in the control range (U+0000–U+001F) that are illegal in raw JSON strings are escaped to \uXXXX form automatically.
Is JSON Escape / Unescape free to use?
Yes. JSON Escape / Unescape on UtilityKit is completely free with no account, no sign-up, and no usage limits.

Explore the category

Glossary

Escape sequence
A backslash followed by one or more characters that represents a character which cannot appear literally in a JSON string — for example \n for a newline or \" for a double quote.
JSON string
A sequence of Unicode characters enclosed in double quotes in a JSON document. Certain characters must be escaped with a backslash to be legal inside a JSON string.
JSON.stringify
A JavaScript built-in function that converts a JavaScript value to a JSON string, applying all required escape sequences automatically. This tool uses it internally for the Escape operation.
JSON.parse
A JavaScript built-in function that parses a JSON string and reconstructs the original value. Used internally for the Unescape operation to correctly decode all escape sequences.
Double-escaped string
A string that has been JSON-stringified more than once, causing escape sequences like \n to appear as \\n. Requires running Unescape twice to restore the original content.
Control characters
Characters in the Unicode range U+0000–U+001F (such as null, bell, and escape) that are invisible and illegal as literal bytes in a JSON string. They must be represented as \uXXXX escape sequences.