Light-Tool: Serialize a JSON object
Turn any JSON object into a string your text nodes can hold
- json_object
- json_str
ComfyUI's data world is full of things that are secretly JSON - API responses, configs, metadata - and a lot of your other nodes only speak in strings. This node is the translator in one direction: it takes a JSON object and serializes it into a compact JSON string. That's the whole job, and it's the missing adapter whenever you have a dict on one end of a wire and a text node on the other.
What it does
One input, json_object, typed as a wildcard (*) so it accepts a dict/object from any node that emits one. One output, json_str. The mechanism is just json.dumps with ensure_ascii=False, which means non-ASCII characters (accents, CJK, emoji) survive intact rather than being escaped to \uXXXX sequences - a genuinely thoughtful touch, and relevant since this pack's author works in Chinese as well as English. If serialization somehow fails, it returns {} rather than crashing your graph.
The natural companion is the pack's own Deserialize Json String node (the reverse direction) and its KeyValue node (which pulls a value out of a JSON string by dot-notation path). Put together: object → serialize → string → keyvalue or into text nodes, or object → string → deserialize → object. That round-trip pair is the pack's complete JSON toolkit.
Why you'd actually use it
Three jobs. Metadata plumbing: this pack's Save Metadata node wants a JSON string of tags to embed in a PNG - this is the node that produces one from structured data. Prompt/config assembly: when a node outputs a structured object you want to splice into a prompt or a log line, serialize it first. Saving structured data to text: any time a dict needs to ride a text wire (to be written to a file, shown in Show Text, or passed to an API), this is the bridge.
It's a boring, correct, dependency-free adapter - the kind of node that makes a wildcard-heavy graph actually work instead of ending in a type error.
Installing it
Part of ComfyUI-Light-Tool by Hmily. ComfyUI Manager → search "ComfyUI-Light-Tool" → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/ihmily/ComfyUI-Light-Tool
pip install -r requirements.txt
# restart ComfyUI
Pure Python's stdlib json module - no models, no keys, offline.
Where people get burned
- The output is a single-line string.
json.dumpshere doesn't indent, so your pretty multi-line JSON becomes one long line. Fine for plumbing, awkward for eyeballing - run it through Show Text if you want to inspect it, or pretty-print with Show Anything first. - Wildcard input, string output. The input type is loose (
*) but the output is a real string. Don't feed the result into a node expecting a dict - that's what Deserialize is for. {}on failure. A silently-empty result beats a crash, but it also means a broken upstream can hide. Check your object source.
Small, fast, and exactly what it says on the tin. When your graph stops complaining about types, this is often why.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| json_object | * | [object Object] | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| json_str | * | — |