Nested Array Flattener with Source Paths and Two-Way Routing
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.Run the workflow manually; the loader Code node emits one item holding the fictional nested structure under data
- 2.The recursive flatten node walks the structure and emits one flat record per leaf element with source_path and parent_fields
- 3.The IF node checks that qty is not empty and routes each record to the true or false branch
- 4.The true branch tags records qty_present keeping all fields; the false branch passes through a NoOp
- 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
- Import the JSON into n8n and run Execute Workflow manually
- Verify 5 flat records and that source_path matches original locations
- Verify the count entering the IF equals the count leaving the Merge (5=5)
- Try qty null, missing qty, and a nested non-array field (invalid_item)
- 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
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 (7)
Run Demo
Manual Trigger
Load Nested Sample Data
Code
Recursive Flatten with Source Paths
Code
Has Quantity Value?
If
Tag Valid Items
Set
Keep Invalid Items
No Op
Combine Branches
Merge
Note - Setup
Sticky Note
Note - Flattening Rules
Sticky Note
Note - Routing
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