Nodes/comfyui-sg-nodes/Map JSON Array
ComfyUI Node

Map JSON Array

Extract One Field From Every Item in a JSON Array

By sebagallo·Created 9 months ago·Updated 6 months ago· 0
Map JSON Array
    • JSON_ARRAY
    json_array[]
    property_name

    Map JSON Array is the "give me all the IDs" button. Where Map JSON To Property pulls one field out of one JSON object, this one pulls one field out of every object in an array and hands you back a JSON array of the results. Same dot notation, same string output, different scope.

    You'll reach for it whenever an API returns a list and what you actually want is the list of one property. Say a service returns [{"id": 1, "name": "A"}, {"id": 2, "name": "B"}] - feed that in with property_name set to id, and you get ["1", "2"] back on the JSON_ARRAY output. That's a clean, machine-readable list you can pass to whatever consumes a JSON array, or feed onward for further processing. The source also handles nested paths and array indexing the same way as its sibling: user.name, results.0.title, that sort of thing.

    Inputs and output

    • json_array - the JSON array string, e.g. [{"id": 1}, {"id": 2}].
    • property_name - the property to extract from each item, dot notation supported.
    • JSON_ARRAY - the output: a JSON array string of the extracted values.

    One deliberate behavior in the code: items that don't have the requested property (or have it as None) are skipped rather than padded with blanks. So [{"id": 1}, {"name": "x"}] mapping on id gives you ["1"], not ["1", null]. If the lengths don't line up with what you expected, that's why.

    The fine print

    If the input isn't a valid JSON array you get [] back - no error, just an empty array. Values are converted to their string forms since the output is always a JSON string. And since the output is itself a JSON array string, it's a common pattern to chain Map JSON To Property (or Find JSON Element, also in this pack) downstream if you want to reach into the results. Or Map JSON Array on the result again to pull a second level of property out of each item - these three nodes form a tiny JSON query language that covers most real API responses.

    Install

    Ships in comfyui-sg-nodes by sebagallo. Easiest via ComfyUI Manager (search comfyui-sg-nodes), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sebagallo/comfyui-sg-nodes
    

    Restart ComfyUI; it's under SGNodes/JSON. No models, no extra dependencies.

    CategorySGNodes/JSON

    Inputs (2)

    NameTypeDefaultDescription
    json_arraySTRING[]JSON array string (e.g., [{"id": 1}, {"id": 2}]).
    property_nameSTRINGName of the property to extract from each item. Supports dot notation.

    Outputs (1)

    NameTypeDescription
    JSON_ARRAYSTRING