ComfyUI Node

JSON Combine

Merge five objects, later wins

By ComfyUI-Kelin·Created 2 years ago·Updated 4 months ago· 27
JSON Combine
    • json_string
    json_1
    json_2
    json_3
    json_4
    json_5

    When one JSON object isn't enough, merge a stack of them

    If you build structured data in ComfyUI at any scale, you eventually hit the wall where a single JSON Builder isn't enough - you've got a base config block, a couple of optional override blocks, and you need them all smushed into one object for a downstream LLM call or API request. JSON Combine is that merge step: up to five JSON strings in (json_1 through json_5), one merged object out. And the precedence rule is spelled out right in the node's own description: json_5 overrides json_4 … overrides json_1.

    That "later wins" order is the entire personality of this node. It makes it useful for layering: put defaults in the low-numbered inputs, connect real data or user choices into the higher ones, and the higher inputs always win without you writing any logic. It's a poor-man's config overlay, which in a graph editor is genuinely convenient - you can wire a default config, then a per-run override block on top, and the merge just happens.

    How it works

    Each input is parsed as JSON and, if it's an object, its key-value pairs are merged into a running result. Invalid or non-object JSON gets skipped with a warning in the console rather than killing the run - the pack's whole "don't crash the workflow" philosophy in miniature. If an input is already a dict (some pack nodes can pass objects directly), it's merged directly. The output is a single pretty-printed JSON string.

    Inputs and output

    • json_1 … json_5 (all optional, multiline, connectable) - the objects to merge. All five are optional, so a chain of two builders into json_1 and json_2 works fine; empty inputs are ignored.
    • Output: json_string - the merged object, two-space indented.

    Installing

    It's one of twelve nodes in the HuangYuChuh/ComfyUI-LLMs-Toolkit pack. Install once via ComfyUI Manager (search ComfyUI-LLMs-Toolkit), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/HuangYuChuh/ComfyUI-LLMs-Toolkit
    cd ComfyUI-LLMs-Toolkit
    pip install -r requirements.txt
    

    Restart, then find it under 🚦ComfyUI_LLMs_Toolkit/JSON. Dependencies are just Pillow and aiohttp.

    Gotchas

    The main one is precedence, and it's worth repeating because it's the opposite of what some merge tools do: later inputs override earlier ones, so json_5 wins over json_1. Get the order backwards and your "overrides" silently lose. Second gotcha: this is a shallow merge - if two inputs have the same key, the whole value from the later input replaces the earlier one; nested objects don't get deep-merged. And third, remember the output is a JSON string even though the node can accept a dict on an input - if you're handing the result to something expecting an object, wire it into a node that parses JSON, not one that wants native types.

    Category🚦ComfyUI_LLMs_Toolkit/JSON

    Inputs (5)

    NameTypeDefaultDescription
    json_1optSTRING
    json_2optSTRING
    json_3optSTRING
    json_4optSTRING
    json_5optSTRING

    Outputs (1)

    NameTypeDescription
    json_stringSTRING