About this tool
Embedding raw multiline text, source code snippets, or quoted strings into JSON string literals frequently breaks syntax structure. Bare newlines, tabs, and unescaped double quotes violate RFC 8259, throwing fatal 'Unexpected token' parsing errors. This tool provides bidirectional JSON string escaping and unescaping, safely converting plain text into serialized literals and unescaping stringified JSON payloads back into readable human-friendly text.
How to Use This Tool (Step-by-Step)
Enter Raw Text or Escaped String
Paste your raw multiline copy, script snippet, or an already stringified JSON payload into the input pane.
Select Escape or Unescape
Click 'Escape' to serialize delimiters into `\"`, `\\`, and `\n`; or click 'Unescape' to peel away escape slashes and restore formatting.
Copy Escaped String Literal
The sanitized literal displays immediately. Copy with one click to embed directly into application code variables.
Strict RFC 8259 Escape Compliance
Flawlessly sanitizes double quotes, backslashes, line feeds, carriage returns, tabs, and form feeds according to JSON standards.
Smart Unescaping Architecture
Gracefully strips recursive escape slashes, resolving nested serialized payloads back into clean human-readable text.
100% Client-Side Air-Gapped
Transformations run strictly inside local browser memory. Sensitive PEM certificates and API keys remain completely confidential.
String Literal Escaping Gotchas & Tips
- •PEM Certificates in JSON: RSA private keys require literal `\n` characters instead of raw line breaks when placed inside JSON payloads.
- •Beware of Backslash Hell: Stringifying JSON inside JSON multiplies backslashes exponentially. Avoid embedding raw serialized strings inside attributes.
- •Forward slash `/` vs Backslash `\`: Forward slashes can optionally be escaped as `\/` for script-tag defense, but backslashes must always be doubled `\\`.
Code & Transformation Examples
Multiline String Literal Escaping Benchmark
console.log("Line 1\n");
console.log("Line 2");"console.log(\"Line 1\\n\");\nconsole.log(\"Line 2\");"* Double quotes become `\"`, literal line feeds become `\n`, and backslashes become `\\`.
Native JavaScript JSON Stringify Logic
// 利用 JSON.stringify 自动生成合规字面量
function escapeJsonString(str) {
return JSON.stringify(str).slice(1, -1);
}// 利用 JSON.parse 逆向安全还原
function unescapeJsonString(str) {
return JSON.parse('"' + str + '"');
}* Native JSON.stringify handles edge-case Unicode escape sequences with 100% standard fidelity.
Frequently Asked Questions
Q: Why do single quotes fail in standard JSON?
A: RFC 8259 mandates double quotes for strings. Single quotes are strictly invalid in standard JSON and have no escape syntax.
Q: How are Emoji symbols handled during JSON escaping?
A: Modern UTF-8 systems leave emojis intact. Legacy ASCII modes encode them into Unicode surrogate pairs (e.g., `\uD83D\uDE80`), parsing identically.
Q: How does unescaping handle malformed backslashes?
A: The parser features intelligent error tolerance: Non-standard escape sequences are retained as literal characters, preventing syntax exceptions.