ComfyUI Node

JSON Merge

Combine two JSON blobs without picking a winner by hand

By Q-Bug4·Created 2 years ago·Updated about a year ago· 11
JSON Merge
    • merged_json
    json_input_1
    json_input_2
    merge_strategyoverride

    A common shape in JSON-driven workflows: you've got a base config and an override - defaults plus whatever the user actually set - and you need one combined JSON out the other end. Doing that by hand means writing your own merge logic in a script node. JSON Merge does the job with one node and a strategy dropdown, which covers the three ways "combine two JSONs" can reasonably behave.

    How it works

    Feed it two JSON inputs and a merge_strategy, and it walks both structures and combines them according to that strategy. The README gives a clean worked example for the default strategy: input one is {"name": "John", "age": 30}, input two is {"age": 31, "city": "New York"}, and with override the result is {"name": "John", "age": 31, "city": "New York"} - the second input wins wherever the two disagree, and anything unique to either side is kept.

    The inputs and outputs that matter

    • json_input_1 / json_input_2 - multiline strings, the two JSON blobs you're combining.
    • merge_strategy - enum, override / preserve / concat, defaults to override. This is the whole decision the node makes for you: override lets the second input win on conflicting keys (the README's example above); preserve is the inverse - the first input's values are kept where both sides define the same key; concat is for when a key exists in both and holds a list - instead of one replacing the other, the values get combined together rather than one overwriting the other.
    • merged_json (output) - the combined result, as a STRING.

    Picking the right strategy is really the only decision here. Get it backwards - say, preserve when you meant override - and your "new" values silently get dropped in favor of the old ones, which is the kind of bug that's invisible until you notice a setting isn't taking effect.

    How to install it

    Search ComfyUI Manager for "Simple JSON Parser" or "Json Node"; failing that, manual install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Q-Bug4/Comfyui-Simple-Json-Node
    

    Restart. No requirements file, no models - the whole pack is dict manipulation on top of Python's stdlib, so there's nothing extra to fetch.

    Common issues & troubleshooting

    Values disappearing after a merge. Nine times out of ten this is a strategy mismatch, not a bug in the node. If a field you expected to update didn't change, you probably wanted override (second input wins) and had preserve selected instead, or vice versa. Test with the README's own example values first - it's small enough to sanity-check by eye - before trusting the node on your real data.

    concat behaving unexpectedly on non-list values. Concatenation makes sense for keys that hold arrays in both inputs; it doesn't have an obvious meaning for a key that's a plain string or number in both. If you're not sure what a given field will do under concat, test it isolated the way you would merge_strategy generally - feed the node two small JSON blobs with just that one field and check the output before wiring it into a bigger graph.

    Merging more than two sources. This node only takes two inputs at a time. For three or more JSON sources, chain merges - the merged_json output of one JSONMergeNode feeds json_input_1 of the next. It's a bit more wiring, but each step stays inspectable, which matters when you're trying to figure out which merge step introduced an unexpected value.

    Type mismatches between the two inputs. The README's general error-handling note applies here too - if one side is an object and the other's an array at the same path, expect a ValueError rather than a graceful fallback. Merge only really makes sense between two JSONs of the same overall shape.

    Genuinely one of the more useful nodes in this pack if you're doing anything config-driven - defaults plus overrides is a pattern that shows up constantly once you start building JSON-parameterized workflows.

    Categoryutils

    Inputs (3)

    NameTypeDefaultDescription
    json_input_1STRING
    json_input_2STRING
    merge_strategyCOMBOoverride3 options: override, preserve, concat

    Outputs (1)

    NameTypeDescription
    merged_jsonSTRING