Aggregate items into a JSON collection

I’m using an iterator to aggregate N sub-objects into a single JSON object that will be sent as a string in a single API call. The sub-objects are named “tempX_audio” (X is sequential from 1 to N) and they’ll contain the same fields. Just note the API won’t accept an array - the sub-objects must be fields in a parent object. Desired output format is:

{
    "temp1_audio": {
      "robot": "z",
      "url": "y"
    },
    "temp2_audio": {
      "robot": "z",
      "url": "y"
    }
...
}

N varies with each execution, but will be known for each execution when the iterator starts.

I have tried string aggregators after the iterator is closed by an array aggregator (gets an array, but not a collection). I’ve tried building a string variable within the iterator loop (kept getting missing value error). I’m pretty new to Make.com and cannot figure out what must be a straightforward pattern to add dynamically named fields to a collection.

Guessing I need a pattern for this: within an iterator loop, sequentially add a module’s output bundle to a single collection, dynamically naming the field with the current iteration. Then, convert the whole collection to a string.

How can I do this? Thanks!

@Kevin_Flaherty You can use a text aggregator? Or is it a different kind of value you are looking for.


Here you setup the JSON, which then looks like this:

You only have to add another opening and closing brackets for the JSON.

3 Likes

Oh…This is perfect! I had tried the Text Aggregator outside the loop or inside but referencing a different module and making the output more complicated.

This is exactly what I needed. Thank you!

1 Like

Kevin, have a look at the docs on these – using the aggregator tools in general is a snap once you know they are everywhere in Make.

1 Like

No problem @Kevin_Flaherty !
The iterators and aggregators are a nice function. Let me know if you have any other questions

2 Likes