Single/Array Payload Normalizer with Parent-Derived Semantic Array Names
Loading workflow…
Workflow Description
Self-contained workflow emitting five fictional payloads (single object, array, null, invalid string type, and one where customer is already an array). An If node checks Array.isArray(invoice.lines) and routes to genuinely different branches: arrays pass through a noOp with original counts, while single payloads are pre-wrapped into one-element arrays with their original shape recorded. A Merge node in append mode with two inputs joins both branches into one shared naming engine that derives each array name dynamically from the parent field key ('invoice_' + key), preserves scalar fields in a scalars map, and sorts deterministically by payloadId.
How it works
- 1.Run the manual trigger; the Code node emits five test payloads
- 2.The If node checks whether invoice.lines is an array: true passes through a noOp unchanged, false pre-wraps single objects into arrays and records _originalShape (single/missing/invalid)
- 3.A Merge node in append mode with two inputs (index 0 and 1) collects items from both branches
- 4.The naming engine derives semantic names dynamically from parent field keys, keeps scalar fields in scalars, and handles missing/invalid safely (normalized and scalars as empty objects)
- 5.The engine sorts output by payloadId and a noOp hands off structurally unified output ordered PL-001 through PL-005
Use cases
- Normalizing webhook payloads that alternate between a single object and an array
- Dynamic semantic naming of parallel arrays from the parent field key before splitting
- Explicit type validation with scalar preservation, a safe path for missing or invalid payloads and deterministic output order
Requirements
- No credentials; processing is fully local
- For real input: remove the Emit Sample node and connect a Webhook with the same invoice schema directly to the If node
- The If gate is fixed to the invoice.lines path; adjust the expression if your target array path differs — the naming engine works on any fields inside invoice automatically. Branch collection uses a Merge node in append mode with valid input indexes 0 and 1
Setup and testing in n8n
- Import the JSON into n8n keeping active = false
- Execute Manual Trigger and inspect Unified Output Handoff: five items ordered PL-001 through PL-005
- Verify PL-001 is wrapped into one-element arrays with id kept in scalars, PL-002 keeps count 2 via the pass-through branch, PL-003 has normalized = {} and scalars = {} with missing, PL-004 has normalized = {} with invalid and id retained in scalars, PL-005 passes customer as a two-element array and wraps single lines
- Add a new field inside invoice in the sample to confirm the semantic name is derived automatically without code changes
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 (8)
Manual Trigger
Manual Trigger
Emit Sample Webhook Payloads
Code
Is lines Field an Array?
If
Pass Array Payloads Through
No Op
Pre-Wrap Single Payloads
Code
Collect Both Branches
Merge
Semantic Naming Engine and Sort
Code
Unified Output Handoff
No Op
Stage 1 - Sample Payloads
Sticky Note
Stage 2 - Two-Branch Type Gate
Sticky Note
Stage 3 - Naming, Scalars and Order
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