Nodes/comfy-ovum/_.mapObject
ComfyUI Node

_.mapObject

Map, but for dicts — transform every value, or rename keys while you're at it.

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.mapObject
  • py_dict
  • iteratee
  • DICT
iteratee_json

_.map transforms the elements of a list. _.mapObject is the same idea for dicts: it runs an iteratee over every value and hands you a new dict. And thanks to how the port implements it, the iteratee can also rename keys in the same pass - which makes this the node you reach for when you need to reshape a metadata blob or normalize a settings dict before it goes downstream.

What it is

Part of the ovum/underscore family in sfinktah/comfy-ovum, wrapping the mapObject method of underscore3, a Python port of Underscore.js. The iteratee is normalized through _.iteratee, so it accepts the same shorthands as _.map: a function, a key string, an object, or JSON. The port's twist is that a function iteratee can return a (new_key, new_value) tuple - the key half renames the entry, the value half replaces it. Flat map can't rename; this one can.

Inputs that matter

  • py_dict (type *) - the dict to transform. The generator labels object-ish inputs py_dict; any JSON-serializable value works.
  • iteratee (type *, force-input) - an ANY socket for the transform: function, key string, or object shorthand.
  • iteratee_json (STRING, multiline) - JSON or a key selector, used when the socket isn't connected. The save-friendly path.

Output is properly typed DICT - a genuine highlight, since the generator usually stamps * on everything. Feed a _.CHAIN and you get a chain back for continued chaining, resolved with _.value.

Where you'd use it

Metadata cleanup is the classic case: a settings or caption dict arrives with awkward keys and noisy values, and _.mapObject normalizes both in one pass. Rename "cfg_scale" to "cfg", coerce string numbers to actual numbers, strip whitespace - a single function iteratee does the whole reshape. It also pairs naturally with _.keys: get the keys to understand the shape, transform with mapObject, then pass the clean dict to a JSON writer or a downstream formatter.

The caveats

Same family rules apply: functions don't survive a save/reload, so prefer the iteratee_json key-selector form for anything you'll reopen. And remember the dict branch of _.iteratee produces a matcher, not a transformer - if you feed mapObject an object shorthand expecting it to rewrite values, you'll get predicate behavior instead of a transform. Keep the iteratee a function or a plain key when you want actual value changes.

Installing comfy-ovum

ComfyUI Manager: search for comfy-ovum, install, restart. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
pip install -r comfy-ovum/requirements.txt

Restart and you're set. No model downloads, no CUDA - pure-Python utilities. Family caveat stands (work in progress), but _.mapObject is one of the more usable members, and the key-renaming capability is a genuine differentiator.

Categoryovum/underscore

Inputs (3)

NameTypeDefaultDescription
py_dictopt*Primary input object (expected object). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining.
iterateeopt*iteratee: ANY input to override widget. Accepts function, key string, or object shorthand.
iteratee_jsonoptSTRINGiteratee_json: JSON or key selector. Used when 'iteratee' input is not connected.

Outputs (1)

NameTypeDescription
DICTDICT