Can we unflatten items to a JSON

My JSON input has nested arrays and thus I flattened it for ease of renaming and setting. Is there a items to JSON unflattening node?

Step 1) IP:

[
{
name: “Jam”,
cars: [“Honda”, “BMW”]
},
{
name: “Mat”,
cars: [“Toyota”]
}
]

Step 2) Flattened transformed intermediate data structure I have:

[
{
name: “JAM Good”,
car: “HONDA”
},
{
name: “JAM Good”,
car: “BMW-3”
},
{
name: “Mat”,
car: “TOYOTA”
}
]

Step 3) Desired O/P .json local file content:

{
name: “JAM Good”
cars: [“HONDA”,“BMW-3”]
},
{
name: “Mat”,
cars: [“TOYOTA”]
}

Kindly note, I simplified the data above to get the message across. The actual IP and transformations are complex but in essence I need to go from step 2 to 3.

Thank you,

Hey @Gowthaman_Prabhu, I can’t think of a way to perform this aggregation with the pre-built nodes, but you could use the Function node and a little bit of custom code for this your step 2 > step 3 transformation:

This workflow will return the data structure from your step 3:

image

Hope this helps :slight_smile:

For a more in-depth explanation, check out Count occurrences of each item in JSON - #15 by MutedJam. I’ve copied my existing code from there and simply removed the nested loop (which isn’t required here) and adjusted the names of your fields.

Thanks. That’s the solution I could come up with too…