Power Apps and ParseJSON

In September, we got introduced the ParseJSON function in Power Apps. Some Power Apps creators cheered, but the vast majority were mainly wondering what this was all about.

In this post, we’ll go over what the ParseJSON function, which has appeared in (canvas) Power Apps, does and what it can be used for in practice.

What the heck is ParseJSON?

In Power Platform, solutions are built using connectors. For example, use flow’s List rows function to search for all Accounts.

This action returns account data from the Dataverse in JSON format.

In most cases, we can forget about this JSON altogether, as the account’s data (name, address, etc.) can be accessed directly in the flow.

This is possible because the platform automatically parses the JSON string for our use.

The situation is different when we make our own interface calls. In this case, the Send an HTTP request action returns the return value (body) of the interface. Which most often is in JSON format.

If we want to use the return values as usual, we will have to parse the JSON content ourselves. This is done using the ParseJSON action, in which we describe the structure of JSON (Schema) with its data types.

This has all been possible (in flow) from the very beginning. But in Power Apps, you can’t (easily) do this.

What has this meant in practice?

For example, if Power Apps reads a row from a SharePoint list with JSON-formatted content in one column, you haven’t been able to make much use of this column. From a Power Apps perspective, it’s just text, and it’s not enough. By some miracle, the text should be turned into an object.

But now everything is different!

Let’s take a few examples of what you can do in practice with this new ParseJSON function.

Example – Order lines

Let’s outline a simple Purchase Order app. A single order can contain multiple products. The entire order and its products are stored on a single line in the SharePoint list. One column of the list (Order rows in JSON format) contains the ordered products in JSON format.

Order lines:

One order includes:

We display the content of the order in a Power Apps gallery. The products included in the order are on the line in JSON format, but from a Power Apps perspective, the content is just text. For example, we cannot display the content of an order in its own gallery.

Except that now we can.

We create a gallery, such that the values (items) are parsed using (order rows in JSON format) in the table. However, we are not quite finished yet.

The following code

Table(ParseJSON(Gallery1.Selected.'Order rows in JSON format'))

Returns a table that does have the correct rows (3pcs of records from JSON content). But we still need to pick up the desired fields for display. At the same time, we define their data types using the TextValue, etc. functions.

The easiest way to do this is to add a new column to the table for each field.

AddColumns(
    Table(ParseJSON(Gallery1.Selected.'Order rows in JSON format')),
    "item", Text(ThisRecord.Value.item),
    "qty", Value(ThisRecord.Value.qty),
    "unitprice", Value(ThisRecord.Value.unitprice),
    "totalprice", Value(ThisRecord.Value.totalprice),
    "comments",b Text(ThisRecord.Value.comments)
)

Look here!

Now we can present the products of the selected order in their own gallery.

We could make an application where

  • User creates orders
  • 0-n products are picked for each order
  • The order is stored in its entirety on a single line in the SharePoint list
  • Orders can be browsed and edited afterward

Of course, it is not always worth doing something, even if it is possible.

In such an implementation, it is difficult for us to:

  • Count how many products the orders contain.
  • Search for products within orders.
  • Update order lines in bulk
  • etc

But the same concept can be used for something more sensible. For example, Azure Blob stores backups of the orders daily in JSON format. You can use ParseJSON to build Power Apps to browse these backups, created in Blob, in a readable format.

Example 2 – Restore data from flow to Power Apps

From Power Apps, you can trigger a flow, which retrieves data and returns it to the Power App.

Below is a flow that starts from Power Apps and retrieves the apps in the environment and returns them with their data to the calling Power Apps. Since the return message contains not only JSON but also a description of its structure (schema), the result set can be utilized as such, for example, as a gallery value.

But… The Response action is premium and requires a Power Apps license from the app user. This is a problem if everything else in the solution works with standard functionality (no Power Apps license required).

We no longer need the Response action. We can recover data in text format using the standard function (Respond to a PowerApp or flow).

Naturally, we will have to parse the text obtained as a return value (in JSON format) ourselves. For example, like this:

  • In the varAppsJSONText variable, we store the return value from the flow (returnValue, JSON-format string)
  • From the varAppsJSONText variable, we create a table with ParseJSON and AddColumns actions, such that it contains the Power Apps name (Name) and type (AppType))

Note that we can navigate the JSON structure. The app name can be found in the properties record inside JSON.

Text(ThisRecord.Value.properties.displayName)

The formed table can be used as usual in the gallery.

Summary

ParseJSON for Power Apps is quite a handy command. But, as we saw from the examples, citizen developers hardly need it right away.

The function is only in the experimental phase. That is likely to change. So don’t use it in production. For now.

Interested in reading our latest Power Platform blog posts?

You’re welcome to subscribe to our email newsletter: Forward Forever Monthly. Max 1 email per month, with a curated list of latest insights and articles on Power Apps, Power Automate, Power BI.

Leave a Reply