Skip to content
AI Agents

Flatten Subarray Keys into Category Columns with a Sortable Aggregated Inverse Index

9 nodes 9 1 Manual trigger
Download

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. 1.Run the Manual Trigger; a Code node emits a fictional hierarchical object with a variable number of keys
  2. 2.The flatten node decomposes each subarray into rows carrying category, positionIndex, id, name and qty
  3. 3.The inverse-index node aggregates row counts and id lists per category and sorts descending with a rank field
  4. 4.If routes categories with rowCount greater than 2 to one branch and the rest to the other via NoOp endpoints
  5. 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

  1. Import the JSON into n8n and execute the demo manually from the Manual Trigger
  2. Verify flattened rows carry the correct category and zero-based positionIndex
  3. Verify the final output has four items ordered 4,3,2,1 with correct ids
  4. 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

Manual Trigger Code If No Op Merge Set

Details

Trigger Manual trigger
Nodes 9
Apps 6
Views 9
Downloads 1

How to Use

  1. 1.Click "Download Template"
  2. 2.Open your n8n dashboard
  3. 3.Go to Workflows > Import from File
  4. 4.Select downloaded file and configure credentials

Nodes Used (9)

/

Setup & Threshold Docs

Sticky Note

#1

Manual Trigger

Manual Trigger

#2

Emit Hierarchical Sample

Code

#3

Flatten Subarrays into Category Rows

Code

#4

Build Sorted Inverse Index

Code

#5

RowCount Above Threshold?

If

#6

Above Threshold Endpoint

No Op

#7

Below Threshold Endpoint

No Op

#8

Merge Index Branches

Merge

#9

Fix Index Report Fields

Set

#10

Flattened Rows Available (Middle Output)

Sticky Note

#11

Branching & Final Report Docs

Sticky Note

#12
Stay in the loop

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

Be first to discover what is new

Your name, your email, and one confirmation.

Email confirmation · Unsubscribe anytime