How to convert array to a string in Power Automate

“I have a SharePoint column with multiple choices enabled, how can I convert the data from it (array) into a string to send it in a single email in Power Automate?”


Power Automate will automatically add ‘Apply to each’ once you try to use dynamic content from an array. It’s fine if you want to process the items one by one, e.g. update multiple items or send multiple emails. But it’s not so good if you need all the items at once. If you’ve got a SharePoint column with multiple choices, you don’t want to loop through them. You want all of the choices at once, a single string in readable format. It can be user information (emails, names), choices, lookups… The usage is the same: don’t loop, convert the values to a single string.

Simple array

If it’s a simple array with a list of values (no object structure), you can use the join(…) expression. You can see an example of simple array below (created when exporting multiple Person or Group column to .csv):

[
    "xxx@tomriha.com",
    "yyy@tomriha.com"
]

The join(…) expression expects 2 parameters, the array with values, and a separator for the outcome.

join([array], '[separator]')

The example below will take the array (variable var_array), and convert into a comma separated string.

join(variables('var_array'), ', ')

Notes:
variables('var_array') is the array
', ' is definition of the separator, separator are the characters between ' and '

result:
xxx@tomriha.com, yyy@tomriha.com
Power Automate join array into string

Array with objects

It gets a bit more complicated with more complex arrays: Person or Group column, choice column, etc. Instead of just a list of values, complex arrays contain objects with multiple pairs of “key”: “value”.

"Person_MultipleSelection": [
    {
        "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        "Claims": "i:0#.f|membership|xxx@tomriha.com",
        "DisplayName": "Tomáš Říha",
        "Email": "xxx@tomriha.com",
        "Picture": "..."
    },
    {
        "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        "Claims": "i:0#.f|membership|yyy@tomriha.com",
        "DisplayName": "yyy@tomriha.com",
        "Email": "yyy@tomriha.com",
        "Picture": "..."
    }
]

Join(…) expression won’t work here as it would create a string from the whole objects. And you don’t want the whole object, you want just a specific value from that array, e.g. Email.

‘Select’ the values

The best approach is to use the ‘Select’ action. The action expects an array of objects on the input, e.g. the array with multiple users, and allows you to select only some values from it. Put the array as the input, in this example it’s the ‘Person_MultipleSelection’ dynamic content. Since you want to build a string only from the values, you should ignore the key/value mapping and switch to the text mode. That way you can skip the key and select only the values.

Power Automate 'Select' text editor

Each object in the array is represented by the expression item(), and each value by adding ?[‘Key’]. You can use any ‘Key’ from the object. The expressions below will give you all display names or emails of the users.

item()?['DisplayName']
or
item()?['Email']
PA select

Output of the ‘Select’ action will be a new array, this time a simple one, that will contain only the desired values.

PA select outputs

And as was already explained, a simple array can be converted into a string with the join(…) expression

join(body('Select'),';')
->
xxx@tomriha.com;no-reply@tomriha.com
Power Automate convert array of objects into string

Summary

When you convert an array into a string in Power Automate, the first thing to consider is: “what type of array do I need to process”? If it’s a simple array, you can use the join(…) expression. But if it’s a complex array with objects, it’ll require a ‘Select’ action first.

It’s possible to process complex arrays in a single action with a combination of expressions (as when exporting to .csv), but I believe this step-by-step approach has it’s benefits. You can track what’s happening in each step, it’s easier to debug, and much easier to explain and understand.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

2 Comments

Add a Comment

Your email address will not be published. Required fields are marked *