unescape
Make the Literal '\n' Actually Mean Something
- STRING
Every so often your text shows up with escapes as literal characters: "line one\nline two" where the \n is two characters (backslash, n) instead of a real newline. That's what happens when data comes out of JSON, an API, or a file written by something that escaped it on the way out. unescape converts those literal escape sequences back into the real characters. One string in, one properly-escaped string out.
How it works
From StableLlama's Basic data handling pack - and it's the honest version of unescaping, not the scary one. Rather than Python's blanket unicode_escape codec (which can mangle non-ASCII text and occasionally raise), this node does a targeted set of replacements for the control characters that actually matter:
\n→ newline\t→ tab\"→ double quote\'→ single quote\\→ backslash
That covers the overwhelming majority of real cases. The implementation even has a clever bit of ordering - it temporarily parks backslashes so a \\n doesn't get double-decoded into a newline when it shouldn't be. The sibling escape node does the exact reverse (turning real newlines and tabs back into escape sequences), so the two form a round-trip pair.
One input (string), one output (STRING). Nothing to configure.
Where it actually shows up
- JSON payloads - when a node or API returns a string that was JSON-encoded, newlines arrive as literal
\n. Unescape before you split or render. - Generated text - models sometimes emit escaped output; unescape before displaying it or splitting it into lines.
- Config files - values written as
key=value\nwith escapes intact.
The classic pipeline is unescape → then a splitlines node, so you can finally treat that blob as real lines. Feed the unescaped result into splitlines (from data list) and you're in business.
Installing it
Search "Basic data handling" in ComfyUI Manager and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart and it's available. Zero dependencies - this pack is pure Python and nothing else.
Gotchas
This is not a universal unescaper. It handles the five sequences above and nothing else - no \x41 hex escapes, no \u0041 Unicode escapes, no \r. If your data has those, they pass through untouched, and that's a feature (it won't blow up on your text), but don't expect magic. And it only works on literal escape text: if your string already contains real newlines, this node leaves them alone, which is exactly what you want.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |