JSON Length
Know how many items you're dealing with before you loop
- length
The simplest node in an already-simple pack: give it JSON, get back a count. That's it. But it earns its place because of what it feeds - every iterator-driven workflow in this pack (JSONArrayIteratorNode, JSONObjectIteratorNode) needs a bound somewhere so you know when to stop, and hardcoding that number is exactly the kind of thing that silently goes stale the moment your source JSON changes.
How it works
There's no config, no path, no strategy to pick. It counts: array length if you feed it a JSON array, key count if you feed it an object. Under the hood it's len() on whatever json.loads() gave it - no more, no less.
The inputs and outputs that matter
json_input- multiline string, the JSON you want a count of. Can be an array or an object; the node handles either.length(output) - INT, the count. Wire this into a queue-count check, a loop bound, or just a debug display if you want to eyeball how big your data is before running anything against it.
One input, one output. There isn't more to say about the interface - the whole value of this node is that it's this small.
How to install it
Look for "Simple JSON Parser" or "Json Node" in ComfyUI Manager; if you don't find it there, install manually:
cd ComfyUI/custom_nodes
git clone https://github.com/Q-Bug4/Comfyui-Simple-Json-Node
Restart ComfyUI. No dependencies, no models - nothing to fetch beyond the clone itself.
Common issues & troubleshooting
Length of a nested field, not the whole blob. This node counts whatever you hand it directly - it doesn't take a path. If you need the length of something nested three levels deep inside a larger JSON structure, pull that piece out first with JSONParserNode (which has its own array_size output for exactly this, worth checking before you even reach for this node separately) and feed the extracted piece here, or just use the parser's built-in count if that's all you need.
Counting a string that isn't valid JSON. Same error behavior as the rest of the pack - malformed input raises a ValueError rather than returning 0 or attempting a best-effort count. If json_input is coming from somewhere upstream that might occasionally hand you an empty string or plain text instead of real JSON, that's worth guarding against before this node, not after.
Object vs array counting the "wrong" thing. Worth remembering explicitly: for an object, length is the number of keys, not the number of values nested inside those values - a JSON object with 3 keys returns 3, regardless of how deeply nested or how large each individual value is. If you actually wanted a deep item count across a nested structure, this node won't give you that; it only counts the top level of whatever you feed it.
There isn't much of a troubleshooting section to write for a node this small - which is exactly the point of a node this small. It does one unambiguous thing and does it reliably.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| json_input | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| length | INT | — |