Extract objects from within array and create new array

How do I get the format I need for my webhook response?

This is what I need:

{
  "options": [
    {
      "text": {
        "type": "plain_text",
        "text": "*this is plain_text text*"
      },
      "value": "value-0"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "*this is plain_text text*"
      },
      "value": "value-1"
    },
    {
      "text": {
        "type": "plain_text",
        "text": "*this is plain_text text*"
      },
      "value": "value-2"
    }
  ]
}

This is what I have:

[
    {
        "options": [
            {
                "json": "{\"text\":{\"type\":\"plain_text\",\"text\":\"Company 1\"},\"value\":\"record_id_1\"}"
            },
            {
                "json": "{\"text\":{\"type\":\"plain_text\",\"text\":\"Company 2\"},\"value\":\"record_id_2\"}"
            }
        ]
    }
]

This is the setup I am using right now:

My logic is this:

  1. I need to find records in Airtable based of my input
  2. Create an array from the results so I can iterate over it
  3. For each item in the array, create the JSON object in this format:
{
      "text": {
        "type": "plain_text",
        "text": "*this is plain_text text*"
      },
      "value": "value-0"
    },
  1. Combine the JSON objects in an array
  2. Rename the array to options like required for the response and store in variable for later use
  3. Get options variable and send it with the webhook response

I am confused because it seems so simple but it is also late already haha.

Does anyone have an idea that helps to get this done?

Hi @vierless_julian, As far as I’m concerned you don’t need aggregator+iterator modules after search records. Isn’t search records already iterating module ?

As for your problem, I’d directly construct json with a text aggregator. so after search records, just a text aggregator module (source airtable) and a set variable module. Text aggregator input would look like exactly what you’re expecting to get :

{
  "text": {
    "type": "plain_text",
    "text": "*this is plain_text text*"
  },
  "value": "value-0"
}

But in the beggining and in the end you’d have to include

{
“options”: [

and in the end

]
}

To do this you can use if() condition based on Search records bundle position and include first string, and in the end if() condition based on bundle total amount = bundle position (last result). The tricky part is the comma you put between each results. The final result should look like :

if(bundleposition=1;{“options”:[;emptystring){"text:{“type”…“value-0”}if(bundleposition!=bundleamount;,;]})

Mention me if u have more questions
kud