Extract IDs as Array in Power Automate

Extract IDs as Array in Power Automate

I want to share a solution that I recently discovered in Power Automate Flow and Logic Apps. It’s a simple yet powerful technique that can help you extract IDs from a JSON object and convert them into an array of numbers. In my case, I needed this array to use as parameters for another Power Automate Flow action. So, if you’re facing a similar challenge, read on to learn how to solve it.

In other words, I needed something like this:

[1, 2, 3]

This is obviously not so difficult. However, my data was a bit more complex. In detail, my data structure had the following format:

[
    {
        "id": 1,
        "name": "n1"
    },
    {
        "id": 2,
        "name": "n2"
    },
    {
        "id": 3,
        "name": "n3"
    }
]

Right, my data was an array of Json objects. Therefore, I used a Parse Json action from Data Operations to convert my example data into a Json object:

You can skip this, when you already have for instance an output object. As next step I need the right transformation action from Data Operations:

I used the action “Select” and switched the mode from “Map into text mode”:

As result, I got a single input for my mapping:

Now it was on me to convert my input data (my Parse JSON output) into an array of numbers:

I used this parameters:

{
    "inputs": {
        "from": "@body('Parse_JSON')",
        "select": "@item()?['id']"
    }
}

Afterwards, I verified the result by running this small Power Automate Flow in test mode. My input data was transformed as expected into an array of ids:

Summary

To sum up, I found a simple solution to extract IDs from a JSON object in Power Automate Flow and Logic Apps. By using the Select action from Data Operations and switching to “Map into text mode”, I was able to transform my complex data and create an array of numbers containing all the extracted IDs. This technique can save you time and effort, especially if you need to use these IDs as parameters for other Flow actions.

Share
Comments are closed.