Nodes/LF Nodes/Set/Create a Value in a JSON Object
ComfyUI Node

Set/Create a Value in a JSON Object

Write into a JSON object from the graph — the 'set' half of LF's JSON pair

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Set/Create a Value in a JSON Object
  • json_input
  • value
  • ui_widget
  • json
  • json_list
key

Where LF_GetValueFromJSON reads a key out of a JSON object, LF_SetValueInJSON is the writer: give it an object, a key, and a value, and it returns the object with that key inserted or updated. It's the node you reach for when you're assembling structured data in the graph - building a request payload, injecting a value into an LLM context object, or accumulating settings into one JSON blob before you save it.

That last pattern is the killer use case. Say you're generating images from an LLM-produced description plus fixed workflow settings. Instead of keeping five separate string and number nodes floating around, you can funnel them into a single JSON object key by key, then hand that one object to a save node or an API call. One wire instead of five, and the structure is visible in the object itself.

How it works

Three inputs, that's it:

  • json_input - the JSON object to modify. If you're starting from scratch, an empty JSON node (or a {} literal) works fine.
  • key - the field to update or insert. If it exists, the value is overwritten; if not, it's created. That's the entire "Set/Create" of the display name.
  • value - accepts any type, which is why its input type is a wildcard (*). Strings, numbers, booleans, even a nested JSON object. You can build nested structures by setting a value that's itself a JSON object from another node.

It outputs the updated object on json, plus json_list for when you're working in a list context. Feed the json output back into another copy of the node to chain multiple keys - update style, pass the result on, update subject, and so on down the line.

The input that bites

The value input being a wildcard is both the feature and the footgun. Because it accepts anything, ComfyUI will happily let you connect a node of the wrong type and you only find out at queue time. If you're setting a key that should be a number and you've wired in a string, JSON semantics win - the object stores a string and downstream consumers may or may not care.

Installing it

Same pack, same drill:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/comfyui-lf

or ComfyUI Manager → LF Nodes → install → restart. No dependencies, no models. The pack is the legacy frozen repo - the author moved on to lf-nodes - but these JSON nodes are stable and simple enough that frozen is fine.

Where people get burned

  • Overwriting a key you meant to keep. There's no undo inside the node, but since the graph is declarative, the fix is just fixing the key and re-running - nothing stateful.
  • Chaining too many copies and losing track of which key was set where. The KUL_CODE widget pretty-prints the current object on the node body, so glance at that before you go digging.
  • Forgetting the whole pair: this node writes, LF_GetValueFromJSON reads, LF_DisplayJSON shows you the final result. When you're debugging a payload you've built, put a display node at the end and stop guessing.
Category✨ LF Nodes/JSON

Inputs (4)

NameTypeDefaultDescription
json_inputJSONJSON Object.
keySTRINGKey to update or insert.
value*Value to set.
ui_widgetoptKUL_CODE

Outputs (2)

NameTypeDescription
jsonJSON
json_listJSON