JSON Escape / Unescape
JSON Escape / Unescape Tool
Use this JSON Escape / Unescape tool to safely encode and decode JSON string values in seconds. Escaping is essential when you need to embed text that contains quotes, backslashes, line breaks, tabs, or control characters inside a JSON string. Unescaping is the reverse: it converts escaped sequences like \\n and \\t back into human-readable text. This tool runs entirely in your browser, so your data never leaves your device.
Developers often get tripped up when a string that looks fine in the UI fails in an API request or config file. JSON is strict: strings must be wrapped in double quotes, and special characters must be escaped. If you paste a multi-line message directly into JSON without escaping, the parser will throw an error. With a single click, this tool turns raw text into a JSON-safe string, or restores escaped JSON output so you can read it clearly.
What JSON escaping does (and does not do)
Escaping replaces characters that are unsafe in JSON strings with safe sequences. For example, a newline becomes \\n, a tab becomes \\t, a double quote becomes \\\", and a backslash becomes \\\\. Escaping is not the same as URL encoding or Base64 encoding. It does not change the meaning of the content; it only makes it safe for JSON parsers.
When you should escape JSON
- Embedding a user message that includes quotes or line breaks inside a JSON payload.
- Storing text with control characters in JSON configuration files.
- Copying JSON string values from logs or API responses into readable form.
- Preparing test payloads for APIs and webhooks.
- Working with code-generated JSON that uses escaped sequences.
How to use this tool
- Paste raw text or an escaped JSON string into the left editor.
- Click Escape to produce a JSON-safe string, or Unescape to decode it.
- Copy or download the output for use in your payloads or documentation.
Example: escaping a multi-line message
Input (raw text):
Hello "World"
Line 2 with a backslash: C:\temp\file.txt
Line 3 with a tab: A B
Escaped output (safe JSON string value):
Hello \"World\"\nLine 2 with a backslash: C:\\temp\\file.txt\nLine 3 with a tab:\tA\tB
You can now embed the output inside JSON:
{
"message": "Hello \"World\"\nLine 2 with a backslash: C:\\temp\\file.txt\nLine 3 with a tab:\tA\tB"
}
Example: unescaping a JSON string
Input (escaped JSON string):
Line 1\\nLine 2\\nQuote: \\\"ok\\\"
Unescaped output (human-readable):
Line 1
Line 2
Quote: "ok"
Common errors and fixes
- Error: Unexpected token or Invalid JSON. Cause: Unescaped quotes or newlines in a string. Fix: Escape the string before embedding it in JSON, or wrap it in a JSON string literal generated by this tool.
- Error: Invalid escape character. Cause: Using
\before a character that JSON does not allow (e.g.,\q). Fix: Only use valid JSON escape sequences like\\n,\\t,\\r,\\\", and\\\\. - Error: Double-escaped strings (extra backslashes). Cause: Escaping text that is already escaped. Fix: Use Unescape once to normalize, then Escape again if needed.
- Error: Broken Unicode like
\\u00G1. Cause: Invalid hex digits in a Unicode escape sequence. Fix: Ensure Unicode escapes are valid 4-digit hex (0-9, A-F). - Error: Text looks correct but APIs reject it. Cause: JSON strings require double quotes, not single quotes. Fix: Always wrap string values in double quotes in JSON.
Best practices for clean JSON strings
- Escape only string values, not entire JSON objects. If you need to send JSON, use the JSON itself instead of escaping the whole payload.
- Prefer the JSON Validator after escaping to catch syntax errors quickly.
- Use JSON Minifier or JSON Formatter once your string is safe and the JSON is valid.
- If you are sending JSON through URLs or query params, combine JSON escaping with URL encoding when required.
Escaping vs other encodings
JSON escaping is often confused with URL encoding, Base64 encoding, or HTML entity encoding. These are different tools for different problems. JSON escaping is only about making a string valid inside a JSON document. URL encoding makes a string safe for query strings and URLs, Base64 encodes binary data into ASCII, and HTML entities are used to render special characters safely in HTML.
A common workflow is: escape the string for JSON, then URL-encode the JSON if it must be sent in a query parameter. If you are embedding JSON inside HTML, you may also need to HTML-escape to prevent markup issues. This tool focuses solely on JSON string safety, which keeps your payload valid and parsable.
Quick checklist
- Use double quotes for JSON strings, not single quotes.
- Escape newlines and tabs before embedding text in JSON.
- Avoid double-escaping by unescaping once before re-escaping.
- Validate the final JSON with JSON Validator.
FAQs
Is JSON escaping the same as URL encoding?
No. URL encoding replaces characters with percent codes (e.g., %20). JSON escaping uses backslash sequences like \\n or \\\".
Should I escape an entire JSON object?
Only if the entire JSON is being stored as a string value. Otherwise, send the JSON object as JSON, not as an escaped string.
Why do I see double backslashes?
Many logs display escaped strings with extra backslashes. Use Unescape once to return to normal text.
Does this tool handle Unicode?
Yes. Unicode sequences like \\u263A are supported and will be decoded on unescape.
Can I escape JSON that contains tabs or newlines?
Yes. Tabs become \\t and newlines become \\n.
Is my text uploaded or stored?
No. All conversion happens locally in your browser.
What if my API expects a raw string?
Use Escape to generate a JSON-safe string and embed it as a value. Validate the full JSON before sending.
What is the fastest way to debug escaping issues?
Unescape the value, inspect it visually, then escape it again to ensure the output is correct.
Does this work with Windows file paths?
Yes. Backslashes are escaped automatically so paths like C:\temp\file.txt remain valid in JSON.
Can I escape multiline logs for storage?
Yes. Escaping converts line breaks into \\n so logs can be stored safely in JSON.
Keyword‑targeted phrases
- json escape string
- unescape json
- json string escape
- escape json online
- json unescape tool
Related tools: JSON Validator, JSON Formatter, JSON Minifier, Base64 Encoder, Compare Clips