Nodes/ComfyUI XAV JSON Nodes/XAV Set JSON Value From Ref
ComfyUI Node

XAV Set JSON Value From Ref

Nest whole JSON structures inside your JSON — by reference, not by copy

By XAV-Games·Created 5 months ago·Updated 5 months ago· 2
XAV Set JSON Value From Ref
    • json_ref
    json_ref
    key
    value_ref

    The sibling of XAV Set JSON Value. Same idea - put something at a key - except instead of a typed string, you insert another node's output by reference. Three inputs: json_ref (the target), key (property name or list index), and value_ref, the handle of whatever you're inserting. Note that value_ref is forced to be a wire: you can't type it, it has to come from an output socket. The output is the target json_ref back.

    This is how you build nested JSON with this pack. Create an empty object for the outer structure, build a second object or array for the inner one, then insert the inner ref into the outer at a key. You can also take a whole loaded subtree - say, a settings block you pulled out of a config file with XAV Navigate JSON - and attach it onto a different object. That's the real use case: recombining pieces of parsed JSON into a new document without ever serializing anything in between.

    The mechanism is worth understanding, because it's reference, not copy. The source does obj[key] = value, storing the same Python object the ref points to. So if you insert a nested object and later modify it through its own ref, the copy inside the parent changes too - both paths see one object. That's usually what you want (it's how you edit a nested piece after insertion without re-navigating), but it bites you if you assumed the insert took a snapshot. There's no deep copy anywhere in this pack. If you need a detached copy, there's no node for it - plan around that.

    Two honest limits:

    A dead ref is a silent no-op. If value_ref points at nothing, the insert does nothing and you get the same ref back. Combined with Navigate's quiet None refs on missing keys, a broken chain can "work" while inserting nothing.

    Only real refs survive. Because the input type is STRING, whatever you connect has to be a ref produced by one of these XAV nodes. Feed in a plain string value and it resolves to nothing - you get a null stored, not your text. If you want to insert literal text, use XAV Set JSON Value, which types it as a string.

    That last point explains the one way real numbers and booleans get into your JSON: carry them in from a loaded file. Navigate to a number in some JSON you loaded, and insert it by ref - it stays a number. Typed values can't be created by hand in this pack, only preserved from disk. It's a limitation, but once you see it, it stops surprising you.

    The classic build: XAV Create Empty JSON Object (outer) + Create Empty (inner) → Set JSON Value From Ref to nest the inner into the outer → XAV Save JSON to File to see it. When an LLM or API node upstream hands you structured output, this is also how you tuck its result into a larger payload.

    Install is genuinely zero-dependency - pure Python stdlib, no pip install, no models. ComfyUI Manager → Install Custom Nodes → search "ComfyUI XAV JSON Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/XAV-Games/ComfyUI-XAVJsonNodes
    

    Restart ComfyUI and the whole pack appears under Add Node → XAV/json.

    CategoryXAV/json

    Inputs (3)

    NameTypeDefaultDescription
    json_refSTRING
    keySTRING
    value_refSTRING

    Outputs (1)

    NameTypeDescription
    json_refSTRING