Introduction to Parse JSON in Power Apps | ParseJSON Arrays as Table; Return Array from flow

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone reza here this video is an introduction to the new parse json function in powerapps parse json allows us to parse data in json format be it simple complex or array-based json objects we can leverage the output of the parse json function and use the dot notation or the index function and more to traverse through our json objects this comes in handy in various scenarios especially when we are sending array of data back from power automate to power apps so let's check it out in action [Music] json stands for javascript object notation it is a text format for storing and transporting data we now have a new parse json function that allows us to pass valid json string into untyped objects an untyped object can hold any data structure complex or simple it cannot be used directly and it does require explicit conversion we can use the dot operator and take advantage of the index function in powerapps to navigate an untyped object powerapps 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 head over to settings go to upcoming features search for json and ensure that the parse json function and untype objects feature is turned on [Music] i will insert a text input control where i would be plugging in my json code and let's just begin with a simple json object there is no intellisense in powerapps around json structures if i open up visual studio code and paste in that json object it's a simple object that has four different properties name email age and active name is of type string email is of type string age is a number and active is a boolean value in powerapps i have added a label control here the text for this let's say i would like to display the name field value from this json object the parse json function which converts a json string into an object my json string will come from this text input control so i have a leverage text input control dot text now the moment i do this if you observe the data type that this outputs is an untyped object so powerapps is not going to understand the schema of that json object you would need to know the schema of your json in order to help powerapps to traverse through it so if i need the name property from this json object here if i do dot and type name it still returns an untyped object so i need to transform this into its original data type which is a string and for that i can leverage the text function so i get its value as the output which is tom let's copy this label and make a change let's say i need the email so i will use dot email let's copy this label and change this to age now for age it returns an error because in my json the age field is of type number so here i will have to typecast it to value in order to have the right data type mapped which is number and let's try the active field this one is of type boolean so i will have to ensure that i typecast this to boolean in order to retrieve its value now my json object can also be an array and in this case i have an array of string values let's say in this example i want to get the text of the second item in this array for my label control i'll leverage parse json on my text input controls text property which would return that untyped object now this object is of type array and arrays in powerapps need to be typecasted to table and from this table i need the item that is at index number 2 and for that we have an index function so index of this tabular data the position is 2 dot value once again it only returns untyped objects using the dot notation and existence of these fields is only verified at runtime so what we will have to do here is typecasted to its original data type which in this case is a text so if i typecast this to text it will give me the information of the item in index number 2 which is bmw if i change this to 1 it will return forward if i go to three it will return fiat and if i go outside the bounds of this array or if i try and point to a specific field that does not exist it just won't return any value now json can also hold an array of objects like in this scenario i have an array that has four objects that have different properties within them i would like to show the email address field value of the item in this array that is at index 2. parse json on my json string value this will return that untyped object which i know is in the form of an array so i will typecast this to a table from this table i will pick the item at index number two from here if i do dot value i will get to that specific object in this case and from here i need the email address field so i'll point to email and email is of type string so i will type cast this to text and this should return the email address of the second item in this array if i change this to three it will give me the email address of the third item in the array and so and so forth now another use case is where you would like to represent this json data in a gallery a gallery deals with tabular data and array of items so let's insert a blank vertical gallery control and the layout for this i will pick title subtitle and body the items property for my gallery would be parse json from this text input field type cast this to a table this will return an array within this array i have these objects so in my gallery for this title label control its text property i will use this item dot value which is the object dot from this give me the name and name is of type string so i will type casted to text here i will put the email and on the last option i will get the value of the age field this is of type number so i'm typecasting it using value so we can clearly see that this gallery now has its data coming in based on a json object that we are parsing by leveraging the new pars json function we could also have these complex json structures for example i have a json object that has a field called employees within this i have the array that has the information so let's try and plug that in into this gallery so i've plugged in the json code here this time for the items property of my gallery i will use parse json dot employees because employees is that field in my object that has the array of data and i can leverage the table function to typecasted to that specific data type and from then onwards my formulas are literally the same i have this active field that returns true or false this is of type boolean in my json array for the items property i will use filter this data where this record dot value dot active this will return an untyped object i have to strongly type this subtype boolean so let's do that typecasted to boolean is this equal to true if it is only then show that information and we can see how it is filtering this json object to only give me those employees whose active status is set to true and i could change this to let's say false and it will give me the employees whose active status is false and here my objective is to load data in the form of an array but in the form of a strongly typed array rather than that untyped object that i have to keep traversing through so for that you can also leverage the for all function to loop through the array of information that's coming in from this json object so for each of these tabular values let's go ahead and create our objects let's say i want employee name so i'm just creating a field called employee name the value for this would be this record dot value dot name i will have to strongly type it i know that name is of type text so i'll do that put a comma let's say we need the age so i will say age and this would be as follows get the age typecasted to value since it's a number and i will close this object and close my forall function and now if i evaluate this it will give me a table of strongly typed values this i can store in a variable or a collection returning array of data from power automate flows to power apps the standard action which is respond to an app does not support returning array of information however if we were to get an array of data in the form of json which is what flow works in that information i can pass back as a string and now take the advantage of the parse json function to traverse through the array of data so let's take a use case i need to get the members of a sharepoint group in powerapps i've created a dropdown that has the names of my groups if i pick a specific group and click on get group members this will call my flow which will query sharepoint to get the group members return a json array of objects in the form of a string from flow to apps and powerapps will use parts json to traverse through it so when i say get group members this will return all the group members from this specific sharepoint group i have populated the results in a gallery and i've also populated it in a combo box control which can act like a people picker control only for that specific sharepoint group members help center members this group has only two members so my combo box only loads those two get group members triggers a flow that is connected in my power app the flow triggers from power apps and the parameter that is being passed from powerapps to flow is the name of the group i then leverage the sharepoint http rest api action to query my sharepoint site and i am passing the name of the group so that i can get the users who are part of that sharepoint group the response comes back in json fashion it has a lot of information i only needed two main pieces of information the name of the users in the group and the email address and this entire result set is what i am sending back to powerapp from flow and this is being returned as type text there is no option here to return arrays so when this button is clicked here is where i am running the connected flow i am passing the name of my sharepoint group as a parameter to flow flow returns a property called response that's the return parameter that i'm passing this response that i get i am leveraging parse json function here to convert it to this untyped object and i'm storing it in a variable this variable is what i'm transforming here to table because i know it returns me an array of data of course it will give me untyped values but in my gallery i can then use that same concept of typecasting it back to its original values name is of type string so i use text to get it email is of type string so i use text to retrieve its value in this power app the user can take surveys and i have two different survey types that i've provided training feedback survey and open enrollment feedback survey these are dynamic forms that are being created on the fly and there are templates that are driving these at the back end for my training feedback form if i wanted to add another question so let's say instructor feedback is my question i would like to add to the survey i can directly make that change in the back end system and the power app will reflect those changes now since these surveys are dynamically being created if i was to take one of these surveys and provide my response information and hit submit this would store the data in my backend data source which in this case is a sharepoint list the response of that survey i am storing it in the form of json and this is what the response looks like it's an array that has objects the name of that column the data is the information that the user entered while filling out the survey and that information is what i wanted to present in my home screen for my gallery here i am using parse json same concept parse the data is being stored in the form of text and sharepoint i am retrieving that data which is in json format i'm using parse json i am tabularizing that data since i know it's an array of information and from there all i had to do was traverse through the json array i need the data that the user entered so i'll point to the data field it will return untyped object i know it's of type string so i will type casted to text if you enjoyed this video then do like comment and subscribe to my youtube channel and thank you so much for watching
Info
Channel: Reza Dorrani
Views: 63,317
Rating: undefined out of 5
Keywords: parse json powerapps, introduction to powerapps json, parsejson, untyped objects, Parse JSON, JSON, Parse, Power Apps, powerapps, power apps parse, powerapps parse json, power apps parse json to collection, power apps parse string, powerapps array, return array from flow to powerapps, parse json in powerapps, json array, power apps parse json string, reza dorrani, power apps get json, power apps parse json to table, power apps canvas parse json, return json to powerapps from flow
Id: FqfLiJDdC3Q
Channel Id: undefined
Length: 17min 0sec (1020 seconds)
Published: Mon Sep 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.