2 Ways to Get a Value from a JSON Object in Power Automate

Working with JSON objects is a common task when dealing with data online and Power Automate is no different.

JSON, or JavaScript Object Notation, is the preferred data format used in Power Automate. Within a JSON object, you may often find yourself needing to access specific values during your flow run.

To accomplish this, you can use the Parse JSON action with dynamic content or by directly extracting items with an expression.

This post will show you how to get values from any JSON with these methods.

What is a JSON Object?

A JSON object is a format that is easy for machines to read and write. It is the standard data format used across many API’s and other online services.

In Power Automate, JSON objects are often used to store and transmit data between various actions and connectors.

{
  "students": [
    {"name": "Tim", "age": 20},
    {"name": "Erin", "age": 22},
    {"name": "Rob", "age": 27}
  ]
}

A JSON object consists of key-value pairs, where each key is a string, and the value can be a string, number, boolean, null, array, or another JSON object.

For example, the above JSON object contains a students key with an array value consisting of 3 JSON objects. Each contains name and age keys along with paired values.

In Power Automate, you may encounter JSON objects when working with APIs, manipulating data from a connector, or even simply storing data within your flow for later use.

When working with JSON objects in Power Automate, it’s essential to know how to access and manipulate the various values stored within these objects.

This can be accomplished through the use of built-in Power Automate actions such as Parse JSON as well as using formulas within expressions to retrieve specific data from the JSON object.

Get Values in a JSON Object with the Parse JSON Action

In Power Automate, you can easily parse JSON objects by using the Parse JSON action. This action lets you convert a JSON string into a JSON object which then allows you to easily access items in the JSON as dynamic content.

Follow these steps to use the Parse JSON action.

  1. Add the Parse JSON action to your flow.
  2. Add the reference to the JSON object in the Content field of the Parse JSON action.
  3. Click on the Generate from sample button at the bottom of the action.

This will open Insert a sample JSON Payload menu. This is used to automatically generate a JSON schema based on an example.

The schema is like a map letting Power Automate know what type of values it can expect in the JSON, this will allow the data in the JSON to appear as dynamic content later in the flow.

  1. Paste an example of the JSON you expect in your flow.
  2. Press the Done button in the Inset a sample JSON Payload menu.
{
    "type": "object",
    "properties": {
        "students": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "age": {
                        "type": "integer"
                    }
                },
                "required": [
                    "name",
                    "age"
                ]
            }
        }
    }
}

The Parse JSON action should now have the Schema field populated with a JSON schema for your data.

The above schema is generated for the small JSON object example used in this post.

Now you should see the students, age, and name items available as dynamic content in your flow.

You can now use these values just like any other dynamic content!

Get Values in a JSON Object with Key References and Array Index Numbers

You can also directly access values in a JSON object with expressions involving key references and array index numbers.

outputs('JSON_Object')['students'][2]['name']

For example, to access the third name in the example JSON object, you can use the above expression.

  • outputs('JSON_Object') refers to the Compose action named JSON Object that contains the example JSON.
  • ['students'] will get the student array with 3 objects.
  • [2] will get the 3rd item in the student array. This is the zero-based index number of the third item in the array.
  • ['name'] will get the name value from the 3rd object in the array.

Every value in the JSON object can be access using a combination of keys and index numbers in a similar manner.

Conclusions

You have learned how to extract specific values from a JSON object in Power Automate.

The Parse JSON action and using the appropriate schema, you can access the desired data with dynamic content.

But if you only want a singe value from the JSON, it could be easier to use an expression with key and index references.

How do you extract values from JSON in your flows? Let me know in the comments.

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!