Nodes/Comfyui-PixNodes/JSON Slicer (PixNodes)
ComfyUI Node

JSON Slicer (PixNodes)

Slice a JSON list into chunks — or a range — without losing count

By pixixai·Created 8 months ago·Updated 6 months ago· 24
JSON Slicer (PixNodes)
  • json_data
  • json_data
  • count
  • index
modechunk
length1
index0

Big JSON lists are a pain to process whole. JSON Slicer is the paging tool: it cuts a list into chunks and hands you one chunk at a time, along with the total count so a loop knows when to stop. Think of it as the iterator index for JSON data - you set which slice you want, it gives you that slice and the metadata to drive the loop.

The node has two slicing modes, selected by mode:

  • chunk (default) - the list is divided into groups of length, and index selects which group you get. length=5, index=0 is items 0–4; index=1 is items 5–9. This is the paging mode.
  • range - a straight slice: start at index, take length items. index=10, length=5 is items 10–14. This is the "give me these specific items" mode.

The tooltips in the schema say it plainly: length is "chunk size in chunk mode, slice length in range mode," and index is "chunk index in chunk mode, start position in range mode." Both modes also tolerate a dict input - it's converted to key/value pairs, sliced, and returned as a dict.

The outputs that matter

Three outputs:

  • json_data - the sliced result (list or dict, depending on input).
  • count - the number of chunks in chunk mode, or the total item count in range mode. This is the loop-bound value.
  • index - passes through your requested index, which is handy as a loop counter.

So the canonical loop pattern is: JSON Slicer → feed count into a for-loop start, feed the chunked json_data into the loop body, and inside the loop bump index and re-run the slicer to get the next page. It works with any JSON-ish input too - a JSON string gets parsed first.

Install

Part of Comfyui-PixNodes. ComfyUI Manager → search "PixNodes" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/pixixai/Comfyui-PixNodes

then restart. (The README's manual-install line points at the wrong repo, ComfyUI-AlignLayout - use the URL above.) No models, no extra deps.

The fine print

Chunk mode is what you'll use 90% of the time, and its count is chunks, not items - a 23-item list with length=5 reports count=5 (5 chunks, last one has 3). Get that backwards and your loop runs the wrong number of times. Also, out-of-range requests just return an empty list rather than erroring, which is convenient but easy to mistake for "processing succeeded" - check the result length before you trust an empty page. For structured batch-processing loops, this is the node that keeps the bookkeeping out of your way.

CategoryPixNodes/JSON

Inputs (4)

NameTypeDefaultDescription
json_data*输入数据:支持 JSON 字符串、Python 列表或字典
modeCOMBOchunk2 options: chunk, range
lengthINT11–18446744073709550000Chunk模式下为分块大小,Range模式下为切片长度
indexINT00–18446744073709550000Chunk模式下为块索引,Range模式下为起始位置

Outputs (3)

NameTypeDescription
json_data*
countINT
indexINT