JSON Escape / Unescape
Escape and unescape strings for use in JSON
Escape and unescape JSON strings without rewriting the surrounding payload
When a string is embedded inside a JSON document or a JSON string literal in source code, every quote, backslash, and control character has to be escaped. This page applies and reverses that escaping so you can paste a multi-line snippet, error message, or HTML fragment and get a JSON-safe string ready to drop into a JSON property value. It also reverses the process when you need to read an escaped value back as plain text.
- Paste raw text in escape mode to receive a JSON-safe string with quotes, backslashes, and control characters escaped.
- Paste an escaped JSON string in unescape mode to recover the original text.
- Use the JSON formatter on the surrounding payload after embedding the escaped string to verify the document is still valid.
- For multi-line content, confirm the receiver actually expects literal `\n` sequences instead of real line breaks.
Why string-only escaping deserves its own tool
A lot of escape problems do not require reformatting an entire JSON document. They happen inside one string value: embedded HTML, SQL text, log templates, regex fragments, line breaks, or nested JSON.
If you escape the whole payload again, you often create new problems instead of solving the original one. That is why a dedicated string escaping tool is useful. It separates structure issues from literal issues.
Where escape mistakes usually happen
The worst escape bugs come from nested contexts: JSON containing HTML, HTML attributes containing URLs, URLs carrying JSON parameters, or source code strings containing JSON again. Every additional context increases the chance of escaping the wrong characters.
The safest rule is simple: identify the final syntax context first, then escape for that context only. That guidance belongs on the page because it answers a very common real-world debugging problem.
Best use cases
- Embedding HTML, code samples, or error messages inside JSON API responses.
- Producing inline JSON literals for test fixtures and configuration generators.
- Decoding escaped strings extracted from logs or stack traces.
Common mistakes to avoid
- Escaping twice produces strings such as `\\n` instead of `\n`. Run the operation only once per layer of nesting.
- Some systems use single-quoted strings or YAML-style escaping. JSON escaping uses double quotes and a defined set of escape sequences only.
- Control characters like raw tabs and newlines must be escaped or the resulting JSON will fail to parse.
Related tools
Move directly into the next step instead of leaving the site to do adjacent work elsewhere.
FAQ
When should I escape and when should I just embed an object?
If the value is structured (object, array), embed it as a real JSON value. Use string escaping only when the receiver expects a string field that happens to contain JSON-looking text.
Why does my escaped string have two backslashes?
Because the original text already contained a backslash. JSON requires escaping every backslash, which is why `\` becomes `\\` in the encoded form.
Is unicode handled?
Yes. Characters outside the basic ASCII range can be represented with `\uXXXX` escapes; modern JSON parsers accept the raw UTF-8 form too.