How To Convert An Object To An Array With Power Automate

power automate convert object to array

It is quite common to get some JSON object data of an API that needs to be proceeded. But how do you handle this text wall of JSON in further actions? The trick is basically to use the Parse JSON action to make the values accessible. In this article, you will see step-by-step how to use the data of an JSON object and transfer it to a Power Automate array you can work with as you used to.

In the example, we are working with the following JSON object.

{
  "Contacts": [
    {
      "name": "John Doe",
      "email": "[email protected]"
    },
    {
      "name": "Sally Miller",
      "email": "[email protected]"
    }
  ]
}

The JSON might be some response of a Rest API that provides contact data.

Let’s assume we want to collect all email addresses within the JSON to send emails to every email address.

How To Convert An Object To An Array With Power Automate

  1. Create a new flow

    power automate convert object to array new flow

    Create a new flow

  2. Add a new step by clicking on ‘+ Next step’

    power automate convert object to array new step

    Click Next step

  3. Filter for ‘initialize’ and click on ‘Initialize variable’

    power automate convert object to array initilize variable

    Initialize variable

  4. Set name to ‘myObject’, Type to ‘Object’ and value to the JSON above this guide

    power automate convert object to array init object

    Setup JSON object

  5. Search for ‘pasre json’ and select the Parse JSON action

    power automate convert object to array add parse json

    Add a Parse JSON step

  6. Set Content to myObject by first clicking into Content text field and then on the variable

    power automate convert object to array set to my object

    Set Content of Parse JSON

  7. Click on ‘Generate from sample’

    power automate convert object to array generate from sample

    Generate from sample in Parse JSON

  8. Paste the JSON above this guide into the text field

    power automate convert object to array insert payload

    Insert a sample JSON Payload

  9. Add a new Initialize variable, set Name text field to ‘myArray’ and Type to ‘Array’

    power automate convert object to array add my array

    Initialize array

  10. Add a new step, search for ‘append to array’ and click on ‘Append to array variable’

    power automate convert object to array append to array variable

    Append to array variable

  11. Set Name to ‘myArray’, click into the text field Value and click on ’email’ in the email

    power automate convert object to array email

    Append to array variable action configuration

  12. Since there are multiple emails, automatically an ‘Apply to each’ is created

    power automate convert object to array apply each

    Apply to each

  13. Add a new step by searching ‘Compose’ and click on Compose action

    power automate convert object to array compose

    Add Compose action

  14. Clich in the ‘Inputs’ text field and add the following expression ‘join(variables(‘myArray’),’;’)’

    power automate convert object to array compose inputs

    Join emails

  15. Test run result

    power automate convert object to array result

    Test run result

Leave a Comment

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