Flatten Subarray Keys into Category Columns with a Sortable Aggregated Inverse Index
Read the execution path horizontally, with supporting AI nodes below. Layout changes affect this preview only; the download stays unchanged.
Loading workflow…
Workflow Description
A fully local manual-trigger workflow emits a fictional hierarchical object with four subarrays. A Code node flattens it into rows promoting each subarray key to a category column with a positional index. A second Code node builds an aggregated inverse index counting rows and collecting ids per category, sorted descending with a rank. An If node splits categories above an adjustable threshold into two branches via NoOp endpoints, Merge reunites them losslessly, and a Set node fixes the final report columns.
How it works
- 1.Run the Manual Trigger; a Code node emits a fictional hierarchical object with a variable number of keys
- 2.The flatten node decomposes each subarray into rows carrying category, positionIndex, id, name and qty
- 3.The inverse-index node aggregates row counts and id lists per category and sorts descending with a rank field
- 4.If routes categories with rowCount greater than 2 to one branch and the rest to the other via NoOp endpoints
- 5.Merge appends both branches and Set fixes category, rowCount, ids and rank as the final output
Use cases
- Flattening hierarchical inventory-style data with variable groups before reporting
- Building an inverse index linking each category to its row ids
- Ranking categories by row volume for prioritization
Requirements
- n8n 2.44.6 with code, if, merge, set, noOp, stickyNote and manualTrigger nodes
- No credentials and no network calls — fully local processing
- For real input: replace the sample-emitting node with a source emitting item.json.groups of the same schema; adjust the threshold in the If condition
Setup and testing in n8n
- Import the JSON into n8n and execute the demo manually from the Manual Trigger
- Verify flattened rows carry the correct category and zero-based positionIndex
- Verify the final output has four items ordered 4,3,2,1 with correct ids
- Edge test: add an empty subarray or a non-array key and confirm safe skipping
Service Value
Ready-made workflow template for automation delivery and service execution.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (9)
Setup & Threshold Docs
Sticky Note
Manual Trigger
Manual Trigger
Emit Hierarchical Sample
Code
Flatten Subarrays into Category Rows
Code
Build Sorted Inverse Index
Code
RowCount Above Threshold?
If
Above Threshold Endpoint
No Op
Below Threshold Endpoint
No Op
Merge Index Branches
Merge
Fix Index Report Fields
Set
Flattened Rows Available (Middle Output)
Sticky Note
Branching & Final Report Docs
Sticky Note
Fresh workflows, straight to your inbox
Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.
- New workflows
- Clear overviews
- Setup guides