Nodes/ComfyUI-YogurtNodes/JsonStringify (Yogurt Nodes)
ComfyUI Node

JsonStringify (Yogurt Nodes)

Turn an object back into text — for loggers, LLMs, and API payloads

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
JsonStringify (Yogurt Nodes)
  • data
  • json_string
indent0
ensure_asciifalse
sort_keysfalse

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.dumps only handles JSON-native types - dicts, lists, strings, numbers, bools, None. A tensor, a numpy array, or a custom object will throw a TypeError. 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_keys on and a fixed indent.
  • Unicode mojibake downstream. If the consumer shows \u5f20 instead of the actual character, flip ensure_ascii to off.
  • It's lossless - mostly. Numbers can come back subtly different (1.0 vs 1) 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.

CategoryYogurtNodes/Logic

Inputs (4)

NameTypeDefaultDescription
data*Data to convert to JSON string
indentoptINT00–8Indentation level (0 for compact)
ensure_asciioptBOOLEANfalseEnsure ASCII output
sort_keysoptBOOLEANfalseSort dictionary keys

Outputs (1)

NameTypeDescription
json_stringSTRING