Nodes/LF Nodes/Get Random Key From JSON
ComfyUI Node

Get Random Key From JSON

Grab a random key from a JSON object, reproducibly

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Get Random Key From JSON
  • json_input
  • ui_widget
  • string
seed0

If you've ever wanted a workflow that picks a random prompt, a random character, or a random style from a JSON config file on every run, this is the node. LF_GetRandomKeyFromJSON takes a JSON object, picks one of its keys at random, and hands you that key as a string - seeded, so the pick is reproducible when you want it to be.

It's one of those quiet utility nodes that unlocks a whole workflow pattern. Store your options as a JSON map - {"cyberpunk": "...", "noir": "...", "pastel": "..."} - and this node becomes your random selector. Feed the output into a lookup or a switch, and suddenly your graph can roll a random style, location, or negative prompt without any scripting.

How it works

Two required inputs: json_input, the JSON object you're picking from, and seed, the seed for the random pick. That's the whole input list, which is refreshing. It picks a key - not a value - so think of it as rolling a die over the object's property names.

The single output is string, the chosen key. From there you typically route it into a node that resolves the key back to a value (the pack's JSON get/set utilities do exactly this), or you use the key itself as a label, a filename piece, or a trigger for a switch. A common pattern: combine it with the pack's JSON loading nodes so the whole options table lives in a file you can edit without touching the graph.

The seed is the detail that makes this usable in practice. Set a fixed seed and the pick is deterministic - you can replay a specific run. Randomize the seed upstream and every run rolls a fresh choice. That one knob turns the node from a novelty into a batch-parameter tool.

Installing it

It ships inside LF Nodes, so install the pack:

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

Restart ComfyUI, or grab it from ComfyUI Manager by searching LF Nodes. No runtime downloads; the pack's dependencies are just numpy, Pillow, opencv-python, requests and torch.

Gotchas

Two things to keep in mind. First, it picks keys, not values - a beginner wiring this straight into a prompt will get the key and wonder where the actual text went. You need a second step to look up the value. Second, randomness over keys is uniform: every key is equally likely regardless of what's behind it, so if you want weighted selection you'll have to build that yourself.

Pack note, one last time because it matters if you're starting fresh: comfyui-lf is legacy, frozen at Feb 2025, and development continues in lucafoscili/lf-nodes. The frozen build is stable and plenty usable.

Category✨ LF Nodes/JSON

Inputs (3)

NameTypeDefaultDescription
seedINT00–18446744073709550000The seed for the random pick.
json_inputJSONJSON object from which a random key will be picked.
ui_widgetoptKUL_CODE

Outputs (1)

NameTypeDescription
stringSTRING