Hi community
I am stuck on how to merge an array of collections of arrays, as you can see I want to merge all the arrays by its key name, for example, have one single array of Tasks, how can I achieve this
Hi community
I am stuck on how to merge an array of collections of arrays, as you can see I want to merge all the arrays by its key name, for example, have one single array of Tasks, how can I achieve this
Hi @Jose_Madrigal. Welcome to the community!
First, you need to iterate over the outer Array and get each Collection as a Bundle, already separated by type (Tasks, Agenda etc.). For that you’ll use the map() function.
Then, you iterate again over each inner array (Tasks, Agenda etc.) to output individual values.
After the 2nd Iterator, you Aggregate all the results (Value) it generates, but the Source Module must be the 1st Iterator, which is the one that produced N operations (N = the number of bundles in the outer Array).
Then you’ll have a single array with one Collection {“Value”:”<*>”} for each element in the original inner array.
Next, you Create a JSON that is simply an Array of Text and map the resulting array to it, using the map() function again to extract the values from the Collections.
Add a Router before the first Iterator and do it for each inner array you want to parse.
This is how each branch would look like. The 1st Parse JSON module only recreates your original structure.
And here’s the blueprint for this scenario:
From Array of Arrays Inside Collection to Single Array.blueprint.json
Welcome to the Make community @Jose_Madrigal!
@damato You probably could skip the three middle (Iterator/Aggregator) modules and just use a single “Set Multiple Variables” module.
To do this, you can use these built-in functions:
map
map(complex array; key; [key for filtering]; [possible values for filtering separated by a comma])
flatten
flatten(array)
Here’s an example of how you can use these functions together:
{{flatten(map(1.array; "Tasks"))}}
Let me know if there are any further questions or issues.
— @samliew
P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!
Hi @samliew
Thank you for the tip.
Your solution is ninja-level Make! ![]()
I even tried using the brand new Make Code App with Javascript’s Array.prototype.flat(), which I suppose is what Make does under the hood, but the solution ended up having too much code for a no-code tool. ![]()