ComfyUI Node

Petty Paint Map

Run a real Python expression on every element of a JSON list

By mephisto83·Created 2 years ago·Updated 2 years ago· 3
Petty Paint Map
  • text
  • option
  • data
code

PettyPaintJsonMap extracts a path from every element of a JSON list. This node goes further: it runs an actual Python expression against every element and collects the results. Want each entry's name uppercased? Want model_weight * 2? Want to combine three fields into one string? PettyPaintMap does that in a single node with no Python-code node required. It's the "map with arbitrary logic" entry in the petty-paint pack, the ComfyUI-side integration for Petty Paint, Andrew Porter's web canvas that reimagines doodles through Stable Diffusion.

How it works

text is the JSON (expected to be an array). code is a Python expression - not a statement, not a full program. For each element, the node calls eval(code) with these names available:

  • item - the current element
  • index - its position in the list
  • list - the whole array (yes, it shadows the builtin)
  • option - the optional input, passed through to every call

So 'f"{item["name"].upper()}-{index}"' gives you an indexed, uppercased name per element. It's eval, so you have the whole Python language - f-strings, .get(), len(), anything that fits in one expression.

The trap: this is arbitrary code execution

Let's be blunt about this one. eval runs whatever Python you type, with full access to the ComfyUI process. That's fine when you write the code - it's a great power tool. It's a bad idea to paste an expression from a stranger's shared workflow without reading it first. The ComfyUI custom-node ecosystem has no sandboxing; a malicious code string here is the same class of risk as a malicious node. Keep it to code you wrote and understand.

The inputs and outputs

  • text - any; the JSON list (or already-parsed list).
  • code - STRING; the Python expression to apply per element.
  • option - any, optional; available as option inside the expression.
  • Output: data - any; the list of results.

Installing it

Same pack, same install - ComfyUI Manager, search "petty-paint-comfyui-node":

cd ComfyUI/custom_nodes
git clone https://github.com/mephisto83/petty-paint-comfyui-node

Restart ComfyUI. Declared dependency is Flask==2.1.2; nothing to download.

Common issues

Syntax errors in code throw at runtime, so test in a scratch Python file first if your expression is nontrivial. Remember it's eval - an expression, so no for, no return; if you find yourself needing statements, you've outgrown this node and should use a dedicated Python/exec node. And expect results as a Python list - the pack-wide "add an index downstream" quirk applies.

CategoryPettyPaint

Inputs (3)

NameTypeDefaultDescription
text*
codeSTRING
optionopt*

Outputs (1)

NameTypeDescription
data*