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

Introduction to Parse JSON in Power Apps ParseJSON Arrays as Table; Return Array from flow 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.

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

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 .

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.

Posts Related:

    The text for this let's say i would like - Make Automate

    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.

    DISCLAIMER: In this description contains affiliate links, which means that if you click on one of the product links, I'll receive a small commission. This helps support the channel and allows us to continuetomake videos like this. All Content Responsibility lies with the Channel Producer. For Download, see The Author's channel. The content of this Post was transcribed from the Channel: https://www.youtube.com/watch?v=FqfLiJDdC3Q
Previous Post Next Post