Skip to content
AI Agents

Single/Array Payload Normalizer with Parent-Derived Semantic Array Names

8 nodes 76 5 Manual trigger
Download

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. 1.Run the manual trigger; the Code node emits five test payloads
  2. 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. 3.A Merge node in append mode with two inputs (index 0 and 1) collects items from both branches
  4. 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. 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

  1. Import the JSON into n8n keeping active = false
  2. Execute Manual Trigger and inspect Unified Output Handoff: five items ordered PL-001 through PL-005
  3. 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
  4. 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

Manual Trigger Code If No Op Merge

Details

Trigger Manual trigger
Nodes 8
Apps 5
Views 76
Downloads 5

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

/

Manual Trigger

Manual Trigger

#1

Emit Sample Webhook Payloads

Code

#2

Is lines Field an Array?

If

#3

Pass Array Payloads Through

No Op

#4

Pre-Wrap Single Payloads

Code

#5

Collect Both Branches

Merge

#6

Semantic Naming Engine and Sort

Code

#7

Unified Output Handoff

No Op

#8

Stage 1 - Sample Payloads

Sticky Note

#9

Stage 2 - Two-Branch Type Gate

Sticky Note

#10

Stage 3 - Naming, Scalars and Order

Sticky Note

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