Flattening a nested data structure

Hello the Make community :wink:

I’ve a problem with flattening a nested data structure without using the Iterator module, in order to minimize the number of operations (and tokens).

My Use Case

I receive an “array of orders”, each containing an array of “tickets”. My goal is to create a “flat array” where each ticket is on its own line, while retaining key information from the parent order.

Example (input):
“id”: 80196362,
“plan”: { “name”: “Expo1” },
“partner”: { “name”: “the experience” },
“tickets”: [
{ “id”: 1, “unitary_price”: 29.9 },
{ “id”: 2, “unitary_price”: 19.9 }
]
In my step post array agregator i get this:


And without flatening the structure, i get a code that works, but return only the first ticket and look like:

Expected (output):
{ “ticket_id”: 1, “ticket_price”: 29.9, “plan_name”: “Expo1”, “partner_name”: “the experience” },
{ “ticket_id”: 2, “ticket_price”: 19.9, “plan_name”: “Expo1”, “partner_name”: “the experience” }
]

I tested multiples things since 2 weeks without success, so a help in this would be really appreciated:)

Hey there,

blueprint (2).json (5.6 KB)

Something like this should rearrange the incoming array in the desired structure. Make sure to add any extra variables you need to the iterator that were missing in the example output you provided. You can also change the set variables module to set multiple variables to rename all of them as needed.

Hi Stoyan,

thanks for the reply, but to be fair, I don’t succeed using it, I don’t know what is the: BasicFeeder step…
For now what i get to receive the data is:


and in the iterator, i have;

Don’t know what I’m doing wrong …

Inside of the parseJSON module I just pasted the string you provided as example, just delete that module and replace whatever it is mapped to to what your actual input is.

??? I don’t get it, I don’t have a parse json module Oo

Exactly, but I need it so I can test with your input, so copy the blueprint I sent you but without the parseJSON module, the rest should be the same and reconvert the array as you need it.