JSON stands for Java Script Object Notation.
JSON is a Text format for Storing and Transporting data. We have a New Parse JSON Power Fx function In power Apps ,Power Apps new Parse JSON function can turn a text string into a record or table. This Parse JSON Function will be used to pass a valid JSON String into an Untyped Object .
To handle the most dynamic scenarios with a JSON string, we need to address the fact that Power Fx is a strongly-typed language. The JSON format, in comparison, offers very few data types. Additionally, in a scenario where the JSON payload can change when the Power App is run (as opposed to when it is built) we must have the ability to read the JSON and convert into the types we need from the formulas that need them.
To support this most dynamic of scenarios, we have introduced a new type called Untyped object. It is, in effect, a wrapper for a value or object that can be converted to a concrete Power Fx type at the time the app runs.
An Untyped objects holds any data structures like complex or simple It can’t be used Directly and it needs explicit conversion , We can use dot operator and take advantage of the index function in power apps to navigate an untyped objects. But, Power Apps is strongly Typed so if we need to get the data from that Untyped object we would need to ensure that we restore it by leveraging Text , value , Boolean table etc.
To get started with Parse JSON first Go To Settings ->Upcoming features ->ParseJSON Function and Untyped Objects Enable it
- Insert a Text Input control and write a JSON Code i.e a simple JSON Object
- The Object includes : Name is a type of string and email is a type of string and age is numeric value and active is a Boolean value
ParseJSON Function will convert a JSON string into an object
Here the JSON string will come from Text input control
when we observe that Data type would be “Untyped object” But the power apps won’t accept Untyped object.
Insert a Text Label, To display the name in the object first we need to convert the data type to a string by using Text function
Write the following formula in the Text Property of the Tet Label
Text(ParseJSON(textinput.Text).name) |
It will display the name string in the object
To display the email string just replace the name string with email string in the formula
Text Property of Text Label
Text(ParseJSON(textinput.Text).email) |
It will display the email in the object
To display the age which is a numeric value we need to use value unction in the formula
Text Property of Text Label
Value(ParseJSON(textinput.Text).age) |
To display a Boolean value use Boolean function in the formula
Text Property of Text Label
Boolean(ParseJSON(textinput.Text).active) |
The untyped datatype have to be converted using different Text, Value, Boolean functions in the Power Apps
Parse JSON With Array of Data :
Insert a text input control and write an Array as shown below
To display a particular string in the Array we need to in indicate that index by using “index ” operator in function the
An Array will be received by using a “Table” function in the formula
To display a string of an array Insert a Text Label and write a formula as shown below
In the Text Property of the Text Label write a function
Text(Index(Table(ParseJSON(textinput1.Text)),2).Value) |
It will display the second string in the Array
Parse JSON With Array of Objects :
a JSON can also holds an array of objects
Here i am using an Array which has FOUR objects that has different properties within that
To display the email in the second object i am using the following formula
write a formula in the Text property of the Text Label
Text(Index(Table(parseJSON(txtinput3.Text)),2).value.email) |
Displaying Parse JSON Array in Gallery :
Insert a Gallery to display the Array objects in it , Here i am using a layout “Title,Subtitle,body”
write a formula in the Items property of the Gallery
Table(parseJSON(txtinput3.Text)) |
To display the name string in the gallery
write the following formula in the Text Property of the Title label in the Gallery
Text(ThisItem.Value.name) |
To display the email string in the gallery
write the following formula in the Text Property of the subtitle label in the Gallery
Text(ThisItem.Value.email) |
To display the age value in the gallery
write the following formula in the Text Property of the body label in the Gallery
Value(ThisItem.Value.age) |
complex JSON Array which includes a field “Employees”
write a formula in the Items property of the Gallery
Table(parseJSON(txtinput3.Text).employees) |
To filter active users use the following function
To filter inactive users use the following function
To Load Parse JSON Data in the form of strongly typed array rather than untyped object,
Insert a Button and assign the following function to the Button in the Onselect property of the Button