Nodes/ComfyUI-YogurtNodes/JsonSetPath (Yogurt Nodes)
ComfyUI Node

JsonSetPath (Yogurt Nodes)

Write one value into a nested JSON object without rebuilding it

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
JsonSetPath (Yogurt Nodes)
  • json_data
  • value
  • modified_json
path$.newfield
create_missingtrue
copy_datatrue

The inverse of JsonGetPath - instead of reading a value out of a JSON blob, JsonSetPath writes one in. Point it at a path like $.model.settings.seed, hand it a value, and you get back a modified object with that field set. No need to rebuild the whole nested structure by hand, no chains of dict-merge nodes.

It's a logic node in the YogurtNodes pack (yogurt7771/ComfyUI-YogurtNodes), and it's the closest thing in the JSON family to "mutation without the guilt" - because by default it doesn't mutate anything.

How it works

You give it json_data (object or string), a path, and a value. It walks the path and sets the value at that location. The defaults matter here:

  • create_missing (on) - missing intermediate paths get created as it goes. Set $.a.b.c on {} and you get {"a": {"b": {"c": <value>}}}. Turn it off and a missing path fails, which is useful when you want to catch data-shape drift.
  • copy_data (on) - it operates on a copy and returns the modified copy, leaving the input object untouched. This is the safety that makes SetPath safe to use in a graph where the same JSON feeds multiple branches. Turn it off only if you're deliberately mutating in place for some reason - and then ask yourself why.

The path syntax matches the other JSON nodes: $.users[0].name sets the name of the first element of users. You can also pass a JSON string in and get a modified object back.

Inputs that matter

  • json_data - the object to modify (or its string form).
  • path - where to write. Default $.newfield, so a bare run just adds a top-level key.
  • value - anything: a string, number, dict, list, boolean. Any-type input, so wire in whatever you've got.

Output: modified_json.

Install

Pack-wide routine - ComfyUI Manager (search "YogurtNodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt

Restart, find it under Yogurt Nodes / Logic. No extra dependencies.

Troubleshooting

  • "It modified my other branch too!" Then copy_data wasn't on, or you're sharing an object through a node that mutates. Keep copy_data on, or put a JsonDeepCopy between the shared source and anything that writes. Node graphs pass references, not copies - this is the exact failure DeepCopy exists for.
  • "Nothing happened." Check the path. If a key at the target level is actually a scalar (not a dict), a deeper path can't descend into it - that's a create_missing situation or a wrong path.
  • Arrays. Setting $.items[2].x works only if items is long enough. create_missing doesn't extend lists, so index out of range is a hard miss. Check length first or set at a known index.
  • Ambiguous keys. Keys containing dots collide with the separator; use bracket notation ['a.b'] or escaped dots to target them.

The pattern that makes this shine: build a base config once, then SetPath overrides per-run (seed, prompt, model params) as separate nodes, all feeding one payload. Your workflow becomes "template + a few targeted writes" instead of a wall of merge nodes.

CategoryYogurtNodes/Logic

Inputs (5)

NameTypeDefaultDescription
json_data*JSON object or string to modify
pathSTRING$.newfieldJSONPath expression (e.g., $.users[0].name)
value*Value to set
create_missingoptBOOLEANtrueCreate missing intermediate paths
copy_dataoptBOOLEANtrueCreate a copy instead of modifying original

Outputs (1)

NameTypeDescription
modified_json*