3 Ways to Convert an Array to String in Power Automate

Do you need to convert an array to a string in Power Automate?

Converting arrays to strings can be useful when you need to pass data between different data sources.

For example, you might want to convert the value from a SharePoint person column that allows multiple selections to a single string with the names and email addresses. This way you can use the data in other flow actions such as in the body of an email.

This post is going to show you how to convert an array to a string in Power Automate.

Convert an Array to String with the Join Action

Power Automate provides an easy way to convert an array to a string value through the Join action.

This action will allow you to join all the items in an array and separate them with your chosen delimiter.

This example shows a simple array of string elements ["A","B","C"].

You can use the Join action to convert this array to a single string A, B, C where each of the items from the array is separated by a comma and a space character.

  1. Add a Join action to your flow somewhere after the array to convert to a string.
  2. Add the Dynamic Content reference to your array in the From input of the Join action.
  3. Add your chosen delimiter to the Join with input. This is what will separate the items in your array.

You can use multiple characters in the Join with input to separate your array items. This example uses a comma and space.

📝 Note: You can’t leave the Join with input empty. If you want to concatenate all your array items with no separator, then add a @{null} expression to the input.

Convert an Array to String with the Join Function

Power Automate also has a join function you can use to convert your arrays to strings.

It actually does the exact same thing as the Join action but the advantage is you can use this directly inside another action and avoid the clutter of using an extra step in your flows.

join(outputs('Array_of_Strings'),', ')

The above formula will join the elements of the Array of Strings array with a , separator between each item.

The join function takes an array as the first argument and then the delimiter as the second argument. The delimiter needs to be encased in single quotation marks ‘ to indicate it’s a string value.

💡 Tip: Enter the second argument as '' to join the array items with no separator between the elements of the array.

Convert an Array to String with the Select Action

The previous methods showed you examples of converting an array to a string where each of the elements of the array is a string value.

It’s not always the case you will be dealing with such simple arrays.

Usually, you will be dealing with arrays of more complex objects as their elements.

[
  {
    "Name": "John",
    "Email": "[email protected]"
  },
  {
    "Name": "Sam",
    "Email": "[email protected]"
  }
]

In the above array, each element is a record object which contains multiple key-value pairs.

{"Name":"John","Email":"[email protected]"}, {"Name":"Sam","Email":"[email protected]"}

If you try to use the join action or function with this array, you get something like the above string which is probably not what you wanted.

How can you join only the names from each record in the array?

This can be done with the Select action!

  1. Add a Select action to the flow.
  2. Add the Dynamic Content reference to your array in the From input of the Select action.
  3. Click on the button to Switch Map to text mode for the Map input of the Select action.
  4. Add a reference to the key-value pair in your record to which you want to join. This example will reference @item()?['Name'] to join the name field from each record in the array.

The select action is essentially a loop, that will loop through each item in your array and allow you to select your desired key-value pairs. The items() function allows you to access the current array item of the loop and select it when you’re using the text mode.

The Select action will create a simplified array with only the names as elements ["John","Sam"] and you will now be able to use the Join action to convert this simplified array to a string.

  1. Add a Join action somewhere after the Select action.
  2. Add a Dynamic Content reference to the Select action output in the From input of the Join action.
  3. Add your desired delimiter characters to the Join with input of the Join action.

When you run the flow, you will see the Select action results in the array ["John","Sam"] of names and the Join action will convert this into a single string value John, Sam.

Conclusions

Arrays are a fundamental data type that every Power Automate developer should know how to work with.

Converting an array to a string will sometimes be necessary to use complex data fields in plain text inputs.

The Join action is the easiest way to convert an array into a string as you can benefit from the simple user interface. But if you’re comfortable with using expressions, the join function will do the same as the action.

The Select Action can also be used to convert an array with more complex objects as elements. It allows you to select from key-value pairs, or even just the value of a key-value pair. Then you can use the Join action to convert the simplified array to a string.

Have you ever come across any tricky arrays you needed to turn into a text value? Let me know in the comment below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Subscribe

Subscribe for awesome tech videos 😃

Related Articles

Comments

0 Comments

Submit a Comment

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

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!