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
-
Create a new flow
Create a new flow
-
Add a new step by clicking on ‘+ Next step’
Click Next step
-
Filter for ‘initialize’ and click on ‘Initialize variable’
Initialize variable
-
Set name to ‘myObject’, Type to ‘Object’ and value to the JSON above this guide
Setup JSON object
-
Search for ‘pasre json’ and select the Parse JSON action
Add a Parse JSON step
-
Set Content to myObject by first clicking into Content text field and then on the variable
Set Content of Parse JSON
-
Click on ‘Generate from sample’
Generate from sample in Parse JSON
-
Paste the JSON above this guide into the text field
Insert a sample JSON Payload
-
Add a new Initialize variable, set Name text field to ‘myArray’ and Type to ‘Array’
Initialize array
-
Add a new step, search for ‘append to array’ and click on ‘Append to array variable’
Append to array variable
-
Set Name to ‘myArray’, click into the text field Value and click on ’email’ in the email
Append to array variable action configuration
-
Since there are multiple emails, automatically an ‘Apply to each’ is created
Apply to each
-
Add a new step by searching ‘Compose’ and click on Compose action
Add Compose action
-
Clich in the ‘Inputs’ text field and add the following expression ‘join(variables(‘myArray’),’;’)’
Join emails
-
Test run result
Test run result