Why escape JSON strings
Embedding text with quotes, newlines, or backslashes inside a JSON field requires proper escaping—or parsing fails. Logs full of \n and \" also need unescaping to read.
ComTools JSON Escape (Tools/Json/Escape) runs escape / unescape locally, with an optional forced \uXXXX Unicode mode.
Modes
| Mode | Effect |
|---|---|
| Escape | Plain text → JSON string body (no surrounding quotes) |
| Unescape | Escaped fragment → original text |
| Force Unicode | Emit \uXXXX for non-ASCII when escaping |
| Swap | Swap input/output and flip escape/unescape |
Escape ≈ JSON.stringify(text) without outer quotes; unescape ≈ JSON.parse('"' + text + '"').
Steps
- Open JSON Escape.
- Choose Escape or Unescape; enable Force Unicode if needed.
- Paste text on the left (or Sample).
- Click Run and copy the result.
- Use Swap to convert back and forth.
Nothing is uploaded.
Escape example
Input:
He said "hello"
Line 2
Output sketch:
He said \"hello\"\nLine 2
Embed as:
{ "msg": "He said \"hello\"\nLine 2" }
Unescape example
Input He said \"hello\"\nLine 2 restores real quotes and newlines.
Common scenarios
| Scenario | Tip |
|---|---|
| Nested text in config | Escape, then paste into a field |
| Unreadable log escapes | Unescape |
| ASCII-only transport | Force Unicode |
| Whole document invalid | Use the validator |
| Pretty-print a tree | Formatter |
Notes
- This tool edits string content, not full-document formatting.
- Unescape needs valid escape sequences; broken
\ufails. - Do not “escape” an entire
{...}object unless you intend to embed that JSON as a string.
Related tools
- JSON Validator
- JSON Formatter
- API JSON debug guide
- HTML Encode — entities, not JSON escapes
FAQ
Why no surrounding quotes?
Output is the field interior only—you add the outer quotes in JSON.
Will Chinese become \u?
Usually kept as-is unless Force Unicode is on.
Escape a whole object?
Minify first, then escape that one-line string.