Nodes/ComfyUI-JK-TextTools/JSON Pretty Printer
ComfyUI Node

JSON Pretty Printer

Read the JSON your nodes are actually producing

By Nakamura2828·Created 8 months ago·Updated 8 months ago· 0
JSON Pretty Printer
    • formatted_json
    • is_valid
    • error_message
    json_string{}
    indent2
    sort_keysfalse
    compactfalse

    JSON Pretty Printer is the debugging tool you'll reach for constantly once you're working with JSON in ComfyUI. Detection results, segmentation queries, API responses - any node that emits JSON as a string dumps it into a text widget as one unbroken, eye-bleeding line. This node reformats it with proper indentation so you can actually read what's there.

    It also validates. Every node in this pack that consumes JSON (Detection Query, JSON to BBox) parses whatever string you give it, and when that fails you get a confusing error buried in the console. Running the string through this node first tells you immediately whether it's valid JSON and, if not, what's wrong.

    How it works

    It parses your string with json.loads - if that throws, you get is_valid false and a human-readable error_message instead of a crash. On success it re-serializes with indentation (indent, default 2, max 8) and optional alphabetical key sorting (sort_keys). The compact toggle overrides the indent and squeezes it back to minimal whitespace - handy when you've reformatted for inspection and need the minified version for a downstream node.

    Input:  [{"detect_result":[{"class":"DOG","score":0.9}]}]
    Output:
    [
      {
        "detect_result": [
          {
            "class": "DOG",
            "score": 0.9
          }
        ]
      }
    ]
    

    Inputs and outputs

    • json_string (STRING, multiline) - the JSON to format.
    • indent (INT, 0–8, default 2) - spaces per level.
    • sort_keys (BOOLEAN, optional) - alphabetize keys.
    • compact (BOOLEAN, optional) - minimize whitespace.

    Outputs: formatted_json (STRING), is_valid (BOOLEAN), error_message (STRING).

    Where it fits

    Debugging, mostly, and there's no shame in that. The classic loop: wire a detection node's output → Pretty Printer → a text display node, and suddenly you can see exactly which keys hold the box, whether it's XYXY or XYWH, and what the class names actually are. That's the "read the JSON before you guess the format" step that prevents half the bbox headaches in this pack. It's also a polite habit to keep one in a workflow's corner as a permanent inspector when you're iterating on a detector.

    Installing it

    It's part of ComfyUI-JK-TextTools. ComfyUI Manager → search "JK-TextTools" → install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Nakamura2828/ComfyUI-JK-TextTools.git
    

    Restart ComfyUI. No models, no extra pip packages - pure standard-library JSON handling.

    Gotchas

    It only formats strings, so if your source outputs a real object rather than text, you'll need to stringify first. And remember the output is still just a string - downstream JSON nodes will re-parse it fine, so formatting doesn't break anything, but don't expect the formatted version to be a typed object you can wire into an object slot.

    CategoryJK-TextTools/json

    Inputs (4)

    NameTypeDefaultDescription
    json_stringSTRING{}
    indentINT20–8
    sort_keysoptBOOLEANfalse
    compactoptBOOLEANfalse

    Outputs (3)

    NameTypeDescription
    formatted_jsonSTRING
    is_validBOOLEAN
    error_messageSTRING