ComfyUI Node

JSON To Text

Pretty-print a JSON object for humans or string nodes

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
JSON To Text
  • json_data
  • STRING
indent0

JSON To Text does one thing: takes a JSON object and serializes it back into a string, with optional pretty-printing controlled by an indent setting. It's the other half of the pack's JSON pair - Text to JSON (DebugPadawan_TextToJSON) turns a string into an object, and this turns the object back into a string.

Why bother? ComfyUI nodes that want JSON want an object, but plenty of destinations want a string: a show-text/display node so you can actually read the data, a text file saver, a node that builds an API request body, or an LLM prompt that needs the JSON inline. Pretty-printing matters more than it sounds, too - an unindented {"name": "Alice", "age": 30} is fine for a machine but miserable for a human trying to eyeball a nested structure. With indent set to 2, you get the readable version with line breaks, which is what you want in a display node or a saved debug log.

How it works

It's json.dumps() with a knob. indent is an integer from 0 to 10; at 0 (the default) it emits compact one-line JSON, and anything above 0 pretty-prints with that many spaces per level. Small touch worth knowing: the input socket is forceInput, so you have to wire an actual JSON object in - you can't type a number into it. It's a converter, not an editor.

The inputs and outputs

  • json_data - the JSON object to serialize. Wire this from a JSON-producing node like Text to JSON, an API response parser, or any node that outputs the JSON type.
  • indent - 0 for compact, 1–10 for pretty. Default 0.

Output is a single STRING - the serialized JSON. Pair it with Text to JSON for a round trip: string → object → string, which is also a decent sanity check on whether your JSON is well-formed.

Installation

The node ships in "DebugPadawan's ComfyUI Essentials," installable via ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git

Restart ComfyUI. No models; pure Python json, no extra dependencies for this node.

Gotchas

The common mistakes are both conceptual. First, feeding it a string instead of an object - if your upstream is giving you JSON as text, it'll fail the type check or serialize as a quoted string (in which case you need Text to JSON first, not this node). Second, expecting the compact mode to be human-readable: at indent 0, long nested JSON becomes one wall of text. Set indent to 2 or 4 for anything you're going to actually read.

One quirk of the ecosystem worth remembering: JSON is also a valid text format for prompting LLMs (structured prompting relies on it), so a pretty-printed dump from this node is a perfectly good way to hand an LLM a readable structured context. It's a small, honest utility - the only real failure mode is wiring the wrong thing in.

CategoryDebugPadawan/JSON

Inputs (2)

NameTypeDefaultDescription
json_dataJSON
indentINT00–10

Outputs (1)

NameTypeDescription
STRINGSTRING