Skip to product information

Flatten Nested JSON Arrays in n8n with Code Node

Flatten Nested JSON Arrays in n8n with Code Node

 (200+Reviews)
Regular price £17.99
Regular price £17.99 Sale price
SAVE Sold out
Instant Digital Download
Unlimited Downloads
Lifetime Access in Your Account
🔥
128+ Sold
Popular with n8n builders
23 people viewing
High interest right now
9 added today
Fast-moving digital product
Flatten Nested JSON Arrays in n8n with Code Node

Flatten Nested JSON Arrays in n8n with Code Node

Regular price £17.99
Regular price £17.99 Sale price
SAVE Sold out

Turn nested JSON into clean lead items in n8n

If your API response includes a nested leads array, this n8n workflow helps you flatten it into one item per lead—while keeping parent metadata and converting each lead’s interests into a ready-to-use CSV string.

What this workflow does

  • Manual start: The workflow begins when you run it manually.
  • Creates sample nested JSON: It generates a sample payload that includes a source field and a leads array of lead objects.
  • Splits leads into individual items: Using the flattening logic, it breaks the nested payload.leads array into separate n8n items—one per lead.
  • Adds parent context: Each resulting item is enriched with parent metadata (such as the payload’s source) and the lead’s `array index`.
  • Formats interests as CSV: It also builds an interests CSV string for easier downstream processing (for example, for mapping, exporting, or storage).
  • Summarizes output: At the end, it reports how many lead items were produced and returns an example output item.

Use cases

  • Prepare flattened lead data for database upserts or CRM ingestion.
  • Normalize API responses so you can reliably export leads to CSV or feed them into reporting steps.
  • Make automation nodes downstream simpler by converting nested arrays into one-item-per-record structures.
  • Test and iterate on array-path changes (for example, if your nested array isn’t at payload.leads).

Technical details

  • Nodes used: Code node (core flattening/formatting), Sticky Note (workflow documentation), Manual Trigger.
  • Setup: Replace the sample data step with your real JSON source (e.g., Webhook or HTTP Request), update the array path (currently payload.leads), and adjust carried-over fields to match your payload structure.

Best for: n8n users, automation engineers, and SaaS operators who need reliable nested JSON array flattening in the Code node.

View full details