Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

How to turn array of objects into a single object in Power Automate

Posted on June 8, 2022June 12, 2022 by Tom

“I’ve got an array where each property is a separate object, how can I turn it into a single object using Power Automate flow?”


If you stay only in the Microsoft 365 environment, you probably won’t encounter this problem. Every array is either a simple array or an array with objects. But once you start processing data from other systems it might not be as clear. Instead of a single object you might receive an array of objects with each object representing one property. A format that can make your life quite complicated.

How do you turn it into a single object that’s easy to work with?

Power Automate array into object

Convert the array into a string

I believe that the easiest way is to “brute force” the conversion.

To turn it into a single object you must remove the },{ between the objects and replace them with a comma. But to use the replace(…) expression you’ll need a string, not an array.

string(outputs('Compose'))

Replace the },{ characters

Once you have a string, you can replace some parts of it. In this situation you should replace the },{ with a single comma.

replace(string(outputs('Compose')),'},{',',')

Turn it back into an array

The string now resembles the object, but it’s still a string. You can’t select a value from a string, nor can you navigate in an array-like looking string. You must turn it back into an array with an object using the json(…) expression.

json(replace(string(outputs('Compose')),'},{',','))

Remove the array

The last step is to remove the [ ] brackets representing an array as you don’t need it anymore since it’s a single object. Use the first(…) expression to take only the first (and only) object.

first(json(replace(string(outputs('Compose')),'},{',',')))
Power Automate array into object

And that’s it, you just turned an array of objects into a single object in your Power Automate flow.

Summary

You don’t need a fancy solution for everything when using Power Automate. Sometimes it’s fine to just adjust the data and force it into the desired format. All you have to do is follow your thought process – how would you do that step by step? Turn it into a combination of expressions and move on.


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 thoughts on “How to turn array of objects into a single object in Power Automate”

  1. Joseph says:
    September 7, 2022 at 9:59 am

    Hi, thanks for your shares.
    What about if I d like to use “append to array variable” action, in a context of apply to each (preventing me from using set variable action in concurrency) ?
    The append to array value can’t have the brackets…
    Thanks

    Reply
    1. Tom says:
      September 18, 2022 at 7:00 pm

      Hello Joseph,
      I’m not sure that I understand the situation, but one of the steps in the blog post is removing the [ and ] brackets using the first(…) expression.

      Reply

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

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.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes