escape
Make your text safe for JSON, logs, and code
- STRING
Newlines and quotes are the enemy of clean data. If you've ever saved a string and watched it break a JSON file, a config, or any format that cares about special characters, this node is the quick fix - it turns literal control characters into the escaped text that those formats expect.
What it does
escape converts five characters to their escape-sequence form: backslash → \\, newline → \n, tab → \t, double quote → \", and single quote → \'. So a string containing an actual line break becomes text with a literal \n in it, which is what a JSON file or a log line wants.
One string input, one STRING output. No options - that's the entire node.
The honest caveat
It's not a full json.dumps or Python repr(). It handles exactly those five characters and nothing else - control characters like carriage returns, null bytes, or unicode escapes pass through untouched. If you need complete, spec-compliant escaping, this isn't it. But for the 95% case - text with newlines, tabs, and quotes that's about to go into a structured format - it does the job with no dependency on a JSON library in the graph.
It pairs naturally with the pack's unescape node for the round trip: escape on the way out, unescape on the way back in.
Why you'd reach for it
Preparing text for output. Prompt text or metadata being written to a file that another tool parses. Log lines that shouldn't have raw newlines. Strings destined for a config or code-like format where quotes need to be literal. If you've ever looked at a saved file and seen the formatting collapse, you know the pain this exists to prevent.
Installing
Part of Basic data handling by StableLlama. In ComfyUI Manager search "Basic data handling" → Install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart. Zero runtime dependencies - pure Python stdlib - so there's no extra package to install and nothing that can conflict with your other nodes.
Where people get burned
The five-character limit is the gotcha. People assume escaping means "make this JSON-safe" and then wonder why a carriage return still breaks their file. Check what special characters your target format actually cares about before trusting the result. Also note the source handles backslashes first in its replacement order, so the escapes it generates don't get double-escaped - that part is handled for you.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |