Skip to content
Data & Databases

Nested Array Flattener with Source Paths and Two-Way Routing

7 nodes 66 3 Manual trigger
Download

Loading workflow…

Workflow Description

A fully local workflow: a Manual Trigger feeds a Code node emitting a fictional nested JSON structure, then a recursive flattening Code node turns every leaf array element into one flat record carrying a full dot source_path such as regions[0].stock[2] plus a parent_fields object of serialized ancestor scalars. An IF node splits records by whether qty is non-empty into two independent branches; the true branch tags records via a Set node while the false branch passes through a NoOp, and a two-input append Merge reunifies all items, so counts entering the IF equal counts leaving the Merge, with no external calls.

How it works

  1. 1.Run the workflow manually; the loader Code node emits one item holding the fictional nested structure under data
  2. 2.The recursive flatten node walks the structure and emits one flat record per leaf element with source_path and parent_fields
  3. 3.The IF node checks that qty is not empty and routes each record to the true or false branch
  4. 4.The true branch tags records qty_present keeping all fields; the false branch passes through a NoOp
  5. 5.A two-input append Merge reunifies both branches into one iterable list

Use cases

  • Flattening nested API-style JSON payloads before iteration or merging
  • Tracing which parent array each row came from for auditing
  • Splitting records by field completeness before downstream processing

Requirements

  • No credentials and no external calls; all processing is local
  • To use real input: delete the Load Nested Sample Data node and feed the flattener with output containing an object under data

Setup and testing in n8n

  1. Import the JSON into n8n and run Execute Workflow manually
  2. Verify 5 flat records and that source_path matches original locations
  3. Verify the count entering the IF equals the count leaving the Merge (5=5)
  4. Try qty null, missing qty, and a nested non-array field (invalid_item)
  5. Try a deeper structure by nesting an array inside stock to confirm depth-agnostic flattening

Service Value

Ready-made workflow template for automation delivery and service execution.

Apps Used

Manual Trigger Code If Set No Op Merge

Details

Trigger Manual trigger
Nodes 7
Apps 6
Views 66
Downloads 3

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 (7)

Run Demo

Manual Trigger

#1

Load Nested Sample Data

Code

#2

Recursive Flatten with Source Paths

Code

#3

Has Quantity Value?

If

#4

Tag Valid Items

Set

#5

Keep Invalid Items

No Op

#6

Combine Branches

Merge

#7

Note - Setup

Sticky Note

#8

Note - Flattening Rules

Sticky Note

#9

Note - Routing

Sticky Note

#10
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