JSON stands for JavaScript Object Notation, and it’s a lightweight data language that makes it easy to parse and generate data. JSON is commonly used in web applications to exchange data between the client and the server in a way that both sides can understand, and it’s a handy language to be able to work with during development on the Power Platform. That’s why Microsoft recently rolled out the JSON function for Canvas Apps, providing a handy shortcut to interacting with data in PowerApps. Let’s learn how to take advantage of it!

Basics of the JSON Function

To use the PowerApps JSON function, you first need to have a JSON string. You can get this JSON string from a variety of sources, including a web service, a SharePoint list, or a static file. Once you have your JSON string, you can use the JSON function to parse it into an object, modify it, and then generate a new JSON string.

Example of the JSON Function

Here is an example of how to use the PowerApps JSON function to parse a JSON string:

Set(myJSONString, 
    "{""name"":""John Smith"",
      ""age"":30,
      ""city"":""New York""}"
)
Set(myJSONObject, JSON(myJSONString))

In this example, we first set a variable called myJSONString to a JSON string. We then use the JSON function to parse the JSON string into an object and set it to a new variable called myJSONObject.

Once you have the JSON object, you can access its properties using dot notation. For example, to get the name property from the myJSONObject object, you would use the following formula:

myJSONObject.name

This would return the value “John Smith”.

Example of the JSON Function – Modifying an Object

You can also use the PowerApps JSON function to modify a JSON object. Here is an example:

Set(myJSONString, 
    "{""name"":""John Smith"",
      ""age"":30,
      ""city"":""New York""}"
)
Set(myJSONObject, JSON(myJSONString))
Patch(myJSONObject, {name:"Jane Smith"})
Set(myNewJSONString, JSON(myJSONObject))

In this example, we start with the same JSON string as before. We then use the JSON function to parse the JSON string into an object and set it to a new variable called myJSONObject.

We then use the Patch function to modify the myJSONObject object by changing the name property to “Jane Smith”.

Finally, we use the JSON function again to generate a new JSON string from the modified myJSONObject object and set it to a variable called myNewJSONString.

Example of the JSON Function – From a SharePoint Column

Suppose you have a SharePoint list that contains customer data. The customer data is stored as a JSON object in a column called “CustomerData”. You want to create a PowerApp that allows you to view and edit the customer data.

To do this, use the PowerApps JSON function to parse the JSON object into an object that can be used. Here is an example:

Set(myCustomerJSONString, 
    First(Filter('Customers', ID=1)).CustomerData
)
Set(myCustomerJSONObject, JSON(myCustomerJSONString))

Wrapping Up

PowerApps JSON function has opened up a world of possibilities for Power Platform developers. It allows for easier handling and manipulation of JSON data, making PowerApps faster and more efficient to work with. By using the JSON function in PowerApps, developers save time and end-users enjoy faster loading times, resulting in a better experience. PowerApps continues to solidify its position as a top low-code platform for building custom applications and automating business processes


0 Comments

Leave a Reply

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