How do I map all items from an array value into JSON format?

How do I map the output values from an Array aggregator into individual variables to use as text in a JSON body output? Specifically, I have a webhook which results in a nested Array (generated_images) with anywhere between 4-16 Collections inside. Inside each Collection there is a field “url” with a unique url value. I am wanting to take all 4-16 urls and use them in an API call using a standard JSON body format of:
“image_urls”: [
“URL1”,
“URL2”,
“URL3”
],

I know how I can map each URL to a unique field, but is there a way I can set to extract the values and list them in this format, so whether there are 4 URLS or 16 URLS the API call still works?

You should be able to use the map function to get an array of just the urls.

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

If you need more assistance, please provide the following:

1.

Please share screenshots of the module fields and filters in question? It would really help other community members to see what you’re looking at.

You can upload images here using the Upload icon in the text editor:
Screenshot_2023-10-07_111039

2.

Please export the scenario blueprint file to allow others to replicate the issue. At the bottom of the scenario editor, you can click on the three dots to find the Export Blueprint menu item.

Screenshot_2023-08-24_230826

Uploading it here will look like this:

blueprint.json (12.3 KB)

3.

Please provide the input/output bundles of the modules by running the scenario, then click the white speech bubble on the top-right of each module, save the contents as a bundle.json file, and upload it here into this discussion thread:

Screenshot_2023-10-06_141025

Following these steps will allow others to assist you here. Thanks!

2 Likes

Hi @mattb

If your objective is to aggregate all the URLs in the following format: url1, url2, url3, … from all collections, please follow these steps:

  1. Utilize an iterator to iterate through the “image_gen_results” array.
  2. Use a next iterator to iterate through the “generated_images” array.
  3. Finally, employ a text aggregator to create a comma-separated list of URLs.

Will result a message
“http:msquare.pro/1”,“http:msquare.pro/2”,“http:msquare.pro/3”,“http:msquare.pro/3”,“http:msquare.pro/4”,“http:msquare.pro/5”
you can map this to json directly.

If you require additional assistance, please don’t hesitate to reach out to us.
MSquare Support
Visit us here
Youtube Channel

2 Likes