Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with 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!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

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.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes