Shuffle JSON keys
Randomize the order of your JSON keys — for real this time
- json_input
- ui_widget
- json
Let's be honest about the use case up front: in most JSON you'll ever touch, the order of keys is semantically meaningless - {"name": "x", "value": 1} and {"value": 1, "name": "x"} parse to the same object. So why would you want to shuffle keys? Because key order still matters in a few real places: when you're displaying JSON to a human and want to hide structure patterns, when a downstream consumer (or a human reviewing it) cares about which field came first, and - the practical one - when you're generating variation in a dataset and want each record to look different. This node does that, deterministically.
The inputs are the kind of small, opinionated set this pack favors. json_input is the JSON object you're shuffling. seed (default 0) drives the randomness - same seed, same shuffle, so a "random" result is reproducible, which is the difference between a lottery and a controlled experiment. mutate_source is the interesting one: off by default, meaning the node copies your input and shuffles the copy, leaving the source object untouched. Flip it on and it shuffles in place. The copy behavior is the safe default - you can chain multiple shuffles off the same source without corrupting it - and the in-place mode is the memory optimization for very large objects where you don't want a duplicate dictionary sitting around.
Output is a single json object, the shuffled version. It's marked as an output node, so its natural home is the end of a JSON-processing branch - display it, save it, hand it onward.
The mechanism is exactly what it says: the keys of the input dictionary get randomly reordered per your seed. It's one of those nodes that's trivial to understand and easy to underestimate - but if you're building JSON-based workflows (and LF's JSON family - load, sort, get-value - exists precisely because people do), having a seeded shuffle in the toolbox means you can generate structurally varied data without writing any Python.
Where people get confused: they expect it to shuffle values or shuffle between multiple JSON objects. It doesn't - it only reorders the keys of one object. If you want to randomize the content itself, that's a different job (pair it with random-value or seed nodes from the pack). And worth noting: because mutate_source defaults off, the first time you use it you'll see a copy in the output and might think nothing happened if the input was already sorted - that's the shuffle being subtle, not broken.
Install: ComfyUI Manager → "LF Nodes", or git clone https://github.com/lucafoscili/comfyui-lf into custom_nodes, then restart. And the pack note that applies to every node here: comfyui-lf is frozen in legacy mode (fully functional), with active development in lucafoscili/lf-nodes.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| json_input | JSON | Input JSON object. | |
| mutate_source | BOOLEAN | false | Shuffles the input JSON in place without creating a new dictionary as a copy. |
| seed | INT | 00–18446744073709550000 | Seed for the random shuffle. |
| ui_widgetopt | KUL_CODE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| json | JSON | — |