CRM Crate

Learn to Parse JSON in Power Apps using Power FX formula

You will learn to Parse a JSON object in Power Apps using Power FX formula. Before we start, make sure to subscribe to CRM Crate so that you can stay up to date in the field of Power Platform.

Learn to Parse JSON in Power Apps using Power FX formula

Power Fx is a low-code programming language used in Microsoft Power Platform, primarily in Power Apps. It is designed to be simple and expressive, making it accessible for users with various levels of technical expertise to create and customize apps. Power Fx formulas are used to define logic and behavior within Power Apps. These formulas are similar to Excel formulas and are written in a declarative way.


How to parse a JSON object in Canvas App / Power Apps using Power FX?

The ParseJSON function is used to analyze a valid JSON string, providing an untyped object that represents the structure of the JSON. If the provided text does not adhere to the JavaScript Object Notation (JSON) format outlined in ECMA-404 and IETF RFC 8259, the ParseJSON function may generate errors.

ParseJSON( JSONObjectString )

JSONObjectString – This is a required parameter which represents a JSON structure as a text.

The ParseJSON function yields an untyped object, necessitating the explicit conversion of field values into supported data types. An untyped object in Power Fx is a data type capable of storing various data structures, whether simple or complex. It cannot be utilized directly and mandates explicit conversion to a specific data type. Accessing fields in records within an untyped object is achieved through dot notation, and the existence of these fields is only confirmed during runtime.

The below example demonstrates the parsing of JSON value in our Canvas App.

Learn to Parse JSON in Power Apps using Power FX formula

The below steps demonstrates the implementation of our Canvas App parsing the JSON content.

Step 1: In this demo, we have a stored a JSON structure based string in a label component.

Step 2: Use Power FX “ParseJSON” function to parse the JSON string stored in the label component.

Set( parsedValue, ParseJSON( 'JSONText.Label'.Text ) );
Learn to Parse JSON in Power Apps using Power FX formula

Step 3: Retrieve the Key:Value data from parsed json string as shown below.

Set (Name, parsedValue.Name)
Set (Title, parsedValue.Title)
Set (Name, parsedValue.Name)
Set (Company, parsedValue.Company)
Set (Country, parsedValue.Country)
Set (ResourceID, parsedValue.ResourceID)
json parsing in power app

Step 4: Save, publish and play your Canvas App for validating JSON Parsing feature as shown below.

In conclusion, the ParseJSON function in Power FX serves as a valuable tool for parsing valid JSON strings, transforming them into untyped objects that can encapsulate a wide range of data structures. While providing flexibility for handling diverse data formats, it is essential to be mindful of potential errors that may arise if the input does not adhere to the specified JSON format standards (ECMA-404 and IETF RFC 8259). The resulting untyped object necessitates explicit conversion for accessing and utilizing field values, making it a versatile yet precise function in Power Apps development. Careful consideration of data types and adherence to JSON specifications ensures effective utilization of the ParseJSON function within the broader context of app development in the Power Platform.


5 1 vote
Article Rating
Subscribe
Notify of
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
URL
10 months ago

… [Trackback]

[…] Read More Infos here: crmcrate.com/power-apps/learn-to-parse-json-in-power-apps-using-power-fx-formula/ […]

ein binance Konto er"offnen
4 months ago

Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

Buksan ang Binance Account
4 months ago

Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.