How do I gather all of the item values within a subarray of multiple collections?

I’m trying to gather all of the “url” fields from every collection in my array (of which there may be any number of collections). The screenshot here (and json file) shows the format.

image_gen_results (array)
1 (collection)
generated images (array)
1 (collection)
url1
2 (collection)
url2
etc…

2 (collection)
3…

I’ve attempted to output and map the “generated_images” “url”, but I can only seem to ever pull the values from the Collection 1 of the “image_gen_results” array.

I’ve tried to iterate and aggregate the data, but it doesn’t seem to get me anywhere as the collection is still broken out separately and won’t pull all of the “url” fields in a single list.

My output needs to be in a JSON list with the “url1”,“url2”,…“url8” etc.

I’ve successfully done this for all the URLs in the first collection, just can’t get the 2nd along with them. Any help would be appreciated.

2023-11-16_10-28-36
jsonoutput.json (2.2 KB)

Which formula have you used to map() this @mgbernier ?

I don’t fully get how your input JSON would look like, but if I understand it correctly you want to map the same variable name with an infinite amount of that value.

In this case, you first need to map all the arrays which are within the results array. Once you have all these arrays, you can then again map() that array to retrieve the URLs:

{{map(flatten(map(1.image_gen_results; "generated_images")); "url")}}


Hope this helps you out!
Cheers, Bjorn

1 Like

Wonderful, this is exactly what I was looking for! Haven’t used the flatten function before, so this is a good one for the arsenal, thanks again.

1 Like

@mgbernier For the next challenge you face (you will always have a next one haha), try going step by step and checking the data output.
In my screenshot you can also see I create multiple varriables starting from the first map, then a flatten, and then another map. This way you can debug easier

2 Likes