How to Parse JSON Object to Array in Power Automate

In this Power Automate tutorial, We will discuss what is Power Automate Parse JSON Object and how to parse Json object to array in Power Automate with an example.

In addition, we will also cover how to parse JSON objects to array dynamically in Power Automate.

Also, I will show you how to parse JSON to get the first value from an array using Power Automate.

Parse JSON Object in Power Automate

  1. In Power Automate, the Parse JSON object allows us to take raw JSON output from a request, which also turns it into values that can be used as dynamic content in flow.
  2. Using the Parse JSON action from the action triggers we can convert the object values in Power Automate.

In the following, we will see how to convert the Parse JSON object to Array in Power Automate.

Also, Read: How to Check If a Date is Blank in Power Automate?

Power Automate Parse JSON Object to Array

Let us see how to parse JSON Object to Array in Power Automate.

In this example, we will use the following JSON object to convert it into the array using the Power Automate flow:

{
  "Employees": [
    {
      "Name": "Preeti",
      "Role": "Lead Analyst"
    },
    {
      "Name": "HariPriya",
      "Role": "Associate IT Analyst"
    },
    {
      "Name": "Sonam",
      "Role": "Associate IT Analyst"
    },
   {
      "Name": "Roselin",
      "Role": "IT Analyst"
    }
  ]
}

So we will assume to display the respective employee name and their role in an array format like the below:

[
  "Preeti - Lead Analyst",
  "HariPriya - Associate IT Analyst",
  "Sonam - Associate IT Analyst",
  "Roselin - IT Analyst"
]

Follow the below steps to convert the JSON object to an array:

Step:1

Log into Power Automate, select the instant cloud flow -> select trigger as Manually trigger a flow -> enter the flow name -> click create option.

How to Parse Json Object to Array in Power Automate

Step:2

  • Select +New step and choose Parse JSON action from the action triggers, and pass the JSON object values in Content as highlighted below:
  • In the Schema, choose Generate from the sample, pass the JSON object value, and choose Done. It will automatically generate the JSON schema as below:
Parse Json Object to Array in Power Automate
Parse Json Object to Array in Power Automate

Step:3

Select initialize variable action to Initialize the variable with the variable type as Array to display the JSON object value in an array format.

Initialize array variable in Power Automate
Initialize array variable in Power Automate

Step:4

  • Now select Append to array variable action, select the initialized array variable, and pass the values to be displayed in the array.
  • As we already discussed, we will pass the Employee name and Employee role inside the array.
append array variable action in Power Automate
append array variable action in Power Automate

Step:5

Add a compose action and pass the initialized array variable, which holds the value of the employee name and role in an array format.

Parse Json Object to Array in Power Automate flow
Parse Json Object to Array in Power Automate flow

Step:6

Save and test the PowerAutomate flow, by selecting Test- >Manually -> Run flow as below:

Run Power Automate Flow
Run Power Automate Flow

In the below screenshot, we can see that our flow has run successfully.

Power Automate Parse Json Object to Array
Power Automate Parse Json Object to Array

Now expand the Compose action to view the converted JSON object data to an array format.

Power Automate Parse Json Object to Array example
Power Automate Parse Json Object to Array example

This is how to parse JSON Object to Array in Power Automate.

Check out: Power Automate Condition if a String is Empty

Dynamically Parse JSON object to Array in Power Automate

Here we will see how to dynamically pase JSON object to Array in Power Automate.

  • In this example, we use the below SharePoint Online List. We will filter the values if the Product Quantity is equal to two, and the filtered list items will be stored as Objects dynamically.
  • Later we will use the Parse JSON action to convert the values from the Object type to Array format.
Dynamically Parse JSON object to Array
Dynamically Parse JSON object to Array

The entire Dynamically Parse JSON object to Array flow looks like the below:

Power Automate flow Parse Json Object to Array dynamically
Power Automate flow Parse Json Object to Array dynamically

Follow the below points, to achieve it:

  • In Power Automate, create an instant cloud flow, select the +new step, and add the Get items to trigger action from the action triggers.
  • Configure the SharePoint site address and list name. In the Filter Query, add the below expression:
ProductQuantity eq '2'
Dynamically Parse JSON object to Array example
Dynamically Parse JSON object to Array example

Now initialize two Variables, one is for an Object Variable type and the other is for an Array Variable type as shown below: we will use the initialized variables later in our flow.

Example of Dynamically Parse JSON object to Array
Example of Dynamically Parse JSON object to Array

Now and apply to each action to loop through the list items; in the outputs section, pass the values dynamic content which has stored the filtered list items.

Example of Dynamically Parse JSON object to Array in Power Automate
Example of Dynamically Parse JSON object to Array in Power Automate

Select Add an action and choose the Set Variable action -> Select the Initialized Object Variable (VarObject) and in the value section pass the current item value from the loop.

Dynamically Parse JSON object to Array in Power Automate
Dynamically Parse JSON object to Array in Power Automate
  • Select +New step and choose Parse JSON action from the action triggers, and pass the initialized Object Variable (VarObject) in Content which has JSON object values.
  • In the Schema, choose Generate from the sample and pass the JSON object value and choose Done. It will automatically generate the JSON schema as below:
Power Automate Dynamically Parse JSON object to Array
Power Automate Dynamically Parse JSON object to Array
  • Add a new step and choose Append to array action and in the Name select the initialized Variable array (VarArray) and in the values action pass the Parse JSON values from the dynamic content as below:
  • Here we will parse the JSON value object of Employee Id, Employee Name, Product Quantity, and Approval Status.
Power Automate Dynamically Parse JSON object to Array example
Power Automate Dynamically Parse JSON object to Array example

Add a Compose action and pass the initialized variable array value as an input. Click on the save button to save the Power Automate flow.

Dynamically Parse JSON as object to Array
Dynamically Parse JSON as an object to Array

Once the flow has been saved, select the Test -> Manually -> Run flow option as below:

Run Power Automate Flow
Run Power Automate Flow

In the below screenshot, we can see that our flow has run successfully.

Parse JSON object to Array dynamically in Power Automate
Parse JSON object to Array dynamically in Power Automate

In the SharePoint Online list, we can see the highlighted list items has the Product Quantity of count 2.

Example of Parse JSON object to Array dynamically in Power Automate
Example of Parse JSON object to Array dynamically in Power Automate
  • Expand the Compose action in the flow to view the output, and we can see the Expected result in an array format.
  • It displays the Employee Id, Employee Name, Product Quantity, and Approval Status Values in an array format.
Parse JSON object to Array dynamically in Power Automate flow
Parse JSON object to Array dynamically in Power Automate flow

This is how to dynamically pase JSON object to Array in Power Automate.

Parse JSON to get the first value from an array using Power Automate

For example, here, we will pass the JSON array values in a compose action, and then we will see how to get the first value using the array index.

To achieve this, Follow the below steps:

Step:1

Create an instant cloud flow, enter the flow name, select the manually trigger a flow action, and click the create button.

parse JSON to get the first value from an array using Power Automate

Step:2

Add a compose action from action triggers and pass the JSON object data values below as Input.

{
"Customers": [
  {
    "Name": "Richard",
    "CustomerCode": "58244",
    "CustomerLocation": "France",
    "ContactNumber": 7894561230
  },
  {
    "Name": "Noah",
    "CustomerCode": "14789",
    "CustomerLocation": "Mexico",
    "ContactNumber": 8456789620
  },
  {
    "Name": "Jordan",
    "CustomerCode": "21456",
    "CustomerLocation": "Germany",
    "ContactNumber": 7584963210
  },
  {
    "Name": "Rufus",
    "CustomerCode": "25896",
    "CustomerLocation": "Canada",
    "ContactNumber": 8457962130
  },
  {
    "Name": "Rachel",
    "CustomerCode": "19835",
    "CustomerLocation": "USA",
    "ContactNumber": 8302165479
  }
]}
parse JSON to get the first value from an array using the Power Automate

Step:3

  • Add a Parse JSON action in the content and pass the dynamic content value of the Outputs of the previous compose action.
  • In the Schema, choose Generate from the sample, pass the JSON object value, and choose Done. It will automatically generate the JSON schema as below:
parse JSON to get the first value from an array using the Power Automate flow

Step:4

Select the +New step, add an apply to each action from action triggers, and pass the dynamic content value of Customers from the Outputs of Parse JSON object.

get the first value from Parse JSON array using the Power Automate flow

Add a compose action and apply the below expression as an input value to get the first value from an array by using the array index.

body('Parse_JSON')?['Customers'][0]
get the first value from Parse JSON array using Power Automate flow

Step:5

Save the flow. Run the flow by selecting the Run flow option. Once the flow ran successfully.

power automate parse json get first value example

We can see the expected result value Output of the compose action, which displays only the first value of an array even though it loops through all five items.

parse json get first value using Power Automate flow

This is how to parse JSON to get the first value from an array using Power Automate.

In this Power Automate article, we have learned how to parse JSON to get the first value from an array using Power Automate.

Moreover, you may like some more Power Automate tutorials:

In this Power Automate tutorial, how to parse Json Object to array in Power Automate with an example. In addition, we also covered how to dynamically Parse JSON objects to Array in Power Automate. And how to parse JSON to get the first value from an array using Power Automate.

>