Get JSON Length [LP]
Get JSON Length [LP] — ComfyUI Node Guide
- length
The one-job node in LevelPixel's JSON toolkit: hand it a JSON string, get back how many entries are in it. Small, but it's the piece that turns "loop over this JSON array" from a guess into a real, countable loop bound.
What it's for
If you're driving one of this pack's iterator-style loops (see Iterator, GetIteratorDataImageFolders) off a JSON array instead of a folder scan - say a list of prompts, or a list of API results you need to process one at a time - you need to know how many items you're dealing with before you can set your queue count or your comparison limit. That's this node's entire reason to exist: turn a JSON string into a count you can wire into a limit field elsewhere.
It ships alongside the rest of this pack's JSON group - Get JSON Value, Check JSON Key, Stringify JSON, Merge JSON Node - added together per the changelog (JSON nodes arrived in v1.3.4), with part of the group's origin credited in the README to Comfyui-Simple-Json-Node by Q-Bug4.
Inputs and outputs
json_string(STRING, multiline) - the JSON text you want the length of.
Output: length (INT) - the count. For a JSON array, that's the number of elements; for a JSON object, that's the number of top-level keys. Either way, the behavior follows what you'd get from Python's len() on the parsed structure, so if you're not sure which shape your JSON is, check that first - the number means something different depending on whether you handed it an array or an object.
Installing it
ComfyUI Manager: search "ComfyUI-LevelPixel" (listed as "Level Pixel"), install, restart the server. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/LevelPixel/ComfyUI-LevelPixel.git, restart. No model downloads, no special dependencies - string parsing only.
Common issues
Malformed JSON is the number one thing that'll trip this up - a missing closing bracket, an unescaped character inside a string value, a trailing comma after the last item. If the count doesn't look right or the node errors, paste your string into a JSON validator before assuming the node's broken; parsing failures upstream of the count are the most common cause.
The array-vs-object ambiguity is worth double checking too. If your JSON is a single object like {"name": "foo", "value": 42}, length gives you 2 (two keys), not the string length of anything and not "1 object." If what you actually wanted was the number of items in an array nested inside that object, you'll need to pull that nested array out first (with something like Get JSON Value) before measuring it - this node measures whatever's at the top level of what you handed it, not anything buried deeper in the structure.
Like the other nodes in this pack's JSON group, this one takes plain text (json_string, a STRING), not the parsed JSON object type that Get JSON Value expects - so if you're chaining these together, make sure you're not trying to wire a JSON socket straight into this node's text input; that connection won't be valid without a stringify step in between.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| json_string | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| length | INT | — |