JsonStringify (Yogurt Nodes)
Turn an object back into text — for loggers, LLMs, and API payloads
- data
- json_string
Once you've parsed, merged, and edited JSON objects in your graph, someone eventually needs to see them as text - a log line, an LLM prompt, an API request body, a file. JsonStringify is the reverse of JsonParse: take any object, turn it into a JSON string. Boring, essential, and the first thing you reach for when you want to look at what your JSON nodes have been doing.
It's a logic node in the YogurtNodes pack (yogurt7771/ComfyUI-YogurtNodes), the bookend of the JSON family. Parse at the input boundary, work in objects, stringify at the output boundary - that's the whole architecture.
How it works
It's json.dumps under the hood, with three knobs that map directly onto the library:
indent(default 0) - 0 produces compact, one-line JSON (minimal size, good for API bodies). 1–8 pretty-prints with that many spaces, which is what you want when a human or an LLM has to read it.ensure_ascii(default off) - off keeps non-ASCII characters (CJK, emoji, accents) as-is in the output. On escapes them to\uXXXX, which you want if the downstream consumer chokes on raw unicode.sort_keys(default off) - sorts dictionary keys alphabetically, giving you deterministic output. Turn it on when you're diffing two strings or caching by content hash.
Output is json_string - a plain STRING you can feed into a text save node, a prompt input, or a request body.
Inputs that matter
data- anything JSON-serializable: dicts, lists, scalars, combinations.indent- the one you'll actually change. 0 for machines, 2–4 for eyeballs.sort_keys- on for reproducible output.
Install
Pack-wide routine - ComfyUI Manager (search "YogurtNodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt
Restart, find it under Yogurt Nodes / Logic. No extra dependencies.
Troubleshooting
- "It won't serialize my thing."
json.dumpsonly handles JSON-native types - dicts, lists, strings, numbers, bools, None. A tensor, a numpy array, or a custom object will throw aTypeError. If you're feeding in a tensor, stringify after converting it to a plain list/number. - "Pretty output is eating my API." Compact (indent 0) vs pretty (indent > 0) produces different byte counts and whitespace. Some APIs are fine either way; if you're hashing or comparing payloads, keep
sort_keyson and a fixed indent. - Unicode mojibake downstream. If the consumer shows
\u5f20instead of the actual character, flipensure_asciito off. - It's lossless - mostly. Numbers can come back subtly different (
1.0vs1) because JSON has one number type. Don't round-trip through stringify expecting bit-identical floats.
The habit worth building: stringify anything you're unsure about and wire it to a preview or text-save node. "What did my JSON actually look like at this point in the graph?" is a debugging question this node answers in one connection.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| data | * | Data to convert to JSON string | |
| indentopt | INT | 00–8 | Indentation level (0 for compact) |
| ensure_asciiopt | BOOLEAN | false | Ensure ASCII output |
| sort_keysopt | BOOLEAN | false | Sort dictionary keys |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| json_string | STRING | — |