ComfyUI Node

Json Builder

Screw a JSON object together from two lists, no typing required

By wwsmiao·Created 4 months ago·Updated 4 months ago· 0
Json Builder
    • STRING
    keys
    values
    modeobject
    nested_path

    JsonParser takes JSON apart; JsonBuilder puts it back together. Where the parser is the star of the wwdm-aicd pack, this is the modest sibling - and it's exactly what you want when a TxtReg extraction has handed you the pieces of a record and you need them formatted as one JSON object, whether for an API call, a config file, or metadata you're saving next to an image.

    The inputs are two lists: keys and values. It zips them positionally into an object, and the mode dropdown picks the shape. object builds a plain {"name": "张三", "age": "25"} - the default and the one you'll use 90% of the time. array_of_objects turns each pair into {"key": ..., "value": ...}, which is a specific structure some APIs want. nested builds nested objects, and nested_path controls where they go - give it user.profile and the pairs get buried under that path, which is handy when a downstream consumer expects a particular envelope.

    The one gotcha to know before you wire anything: it does a positional zip and pads the shorter list with empty strings, so mismatched list lengths don't crash - they silently produce blank values. If keys has 3 items and values has 2, you get a key with an empty string value and no error. That's worth remembering when the output looks subtly wrong.

    Mechanically it's just json.dumps with ensure_ascii=False and indent=2, which means the output is pretty-printed multi-line JSON and - important detail - it keeps non-ASCII characters as-is. That's a deliberate, correct choice for a Chinese-language pack: your Chinese keys and values stay readable in the output instead of becoming \uXXXX escapes. The output is a single STRING (not a list, unlike most of the pack), so it goes straight into a save node, an HTTP body, or another text field.

    Install is the same as every node in this pack, and it's genuinely painless because there are no heavy dependencies:

    cd ComfyUI/custom_nodes
    git clone https://github.com/wwsmiao/comfyui-wwdm-aicd.git
    

    Restart ComfyUI, find it under wwdm-aicd. The README's pip install -r requirements.txt step doesn't apply - there is no requirements.txt in the repo, and the node only needs the standard library. The README and code comments are in Chinese, which is a recurring note for this pack but not a functional problem; the node names and widget labels are English.

    Where it fits: the README's own example pipeline is TxtReg extracts order fields → TxtRegSelect filters → JsonBuilder structures them into JSON → TextTemplate formats the output. It's also the natural inverse of JsonParser - if you ever want to round-trip, parser out, builder back. One honest limitation: it only builds from two parallel lists, so genuinely complex nested structures with mixed types are a stretch; for anything fancier you'd be better off with an LLM node or hand-written JSON. But for "I have extracted fields, make me an object," it's one node and it's done.

    Categorywwdm-aicd

    Inputs (4)

    NameTypeDefaultDescription
    keysSTRING
    valuesSTRING
    modeoptCOMBOobject3 options: object, array_of_objects, nested
    nested_pathoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING