cancel
Showing results for 
Search instead for 
Did you mean: 

How to merge all objects in an array

khanh_tran
New Contributor II

I got an array named “group” includes object items as the below picture
Screen Shot 2021-07-26 at 15.22.51
How can I merge all object items to one object? My expected result as the below picture. But, imagine that the number of item is unknown. It can be 3,4,5 , … (n).
Screen Shot 2021-07-26 at 15.24.27

Thank you!

1 ACCEPTED SOLUTION

j_angelevski
Contributor III

That won’t be a problem here, because I’m using destructuring assignment ( the three dots ) before the $group array ...$group, this will always work for every $group array regardless of the array size, you don’t have to get each index from the $group array, just use ...$group, this will destructure the array and will be the same as writing $group[0]... $group[n] multiple times.

View solution in original post

12 REPLIES 12

j_angelevski
Contributor III

Hi @khanh_tran ,

You can use JSON Splitter after this output and split on $group, this will give you only the objects inside the group array then you can use a Group by N snap to group all input data into a single array ( don’t forget to set the setting Group Size to 0 ).

Thank you! But your answer is not my expectation. I need object[0] merge to object[1] and to object[n].

j_angelevski
Contributor III

If you merge all objects into one, the values will be overwritten for the key with the same name in each object. Is this what you want ?

yes, sure. that’s all I want. Because every object will be not duplicated except the key-participant_survey_progress_sk. The field is also group by key, so it’s also not problem.