What's new in Power Platform? - Ep 2

What's new in Power Platform? - Ep 2

Welcome to the Episode 2 of What's new in Power Platform?

Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect at Kerv Digital for Digital Transformation . I've been working with Microsoft technologies for almost 8 years and have spent the last 4 working with Power Platform. I enjoy building creative solutions for our customers using the latest features.

In this episode we will be looking at ParseJSON in Canvas Apps. This function allows you to parse a valid JSON string and return an untyped object. This untyped object will then require conversion to a valid datatype (more on this later!)


Before we dive into how to use the function, you should be aware that this is an experimental feature. Experimental features aren't meant for production use and may have restricted functionality.


Enabling the ParseJSON function

Before use, you need to enable the function by clicking Settings in the command bar, then set the toggle to on.

Screenshot of ParseJSON function

Basic Syntax

ParseJSON(JSONString)        

Converting Untyped Object Datatype

As mentioned earlier, untyped objects must be converted to a valid datatype.


Let's Imagine we have the following JSON string stored in a variable called "JSONString"



{"Name":"Stuart Baxter","YearsInTech":8,"DOB":"1986-08-16","IsMVP":false}        

String: Using the Text() Function we can extract "Name"



Text(ParseJSON(JSONString.Text).Name)        

Numbers: Using the Value() Function we can extract "YearsInTech"



Value(ParseJSON(JSONString.Text).YearsInTech)        

Dates: Using the DateValue() Function we can extract "DOB"



DateValue(ParseJSON(JSONString.Text).DOB        

Booleans: Using Boolean() function we can extract "IsMVP"



Boolean(ParseJSON(JSONString.Text).IsMVP)        


Creating Tables from JSON

Let's extend our JSONString to the following:



[{ "Name": "Stuart Baxter" ,"YearsInTech": 8, "IsMVP":false,"DOB" : "1986-08-16"},{ "Name": "Theo Baxter" ,"YearsInTech": 0, "IsMVP":false,"DOB" : "2017-06-03"}]        

We can collect the details, and add this collection to the items property of a gallery



ClearCollect?(
 ? col_details,?
 ? ForAll(?
 ? ? ? Table(ParseJSON(JSONString.Text)),?
 ? ? ? {?
 ? ? ? ? ? Name: Text(Value.Name),
? ? ? ? ? ?YearsInTech: Value(Value.YearsInTech),
? ? ? ? ? ?DOB: DateValue(Value.DOB),
? ? ? ? ? ?IsMVP: Boolean(Value.ISMVP)
? ? ? ? }? ? 
  )
)        

then from here your gallery will behave as it normally would, for example a label with ThisItem.Name would return "Stuart Baxter" or "Theo Baxter" and so on.

The Solution

In the last episode I introduced you to the Pokédex app, one of the key components of this app is ParseJSON!

I receive a JSON string from a Power Automate Flow that calls the PokéAPI.

This flow returns a list of all Pokémon, we then parse the response into a collection called "AllPokemon" using this formula in the App.OnStart property


Set(? ?
   AllPokemon,
? ?ListallPokemon.Run().listofpokemon);

ClearCollect(
? ? FullList,
? ? ForAll(
? ? ? ? Table(ParseJSON(AllPokemon).results),
? ? ? ? {
? ? ? ? ? ? Name: Text(Value.name)
? ? ? ? }? ? 
    )
);        

This allows me to create a really simple gallery

Screenshot of a gallery showing a list of Pokémon

This formula is added to the OnSelect property of the next arrow:


Select(Parent);
Set(SelectedPokemon,ThisItem.Name);
Navigate(Pokedex,Fade);        

This action passes the Name of the selected Pokémon to a variable called SelectedPokémon to be handled in the Pokédex Screen

The OnVisible Property of the Pokédex screen contains this formula:


Set(ReturnedPokemon,
??
FindaPokemon.Run(SelectedPokemon).outputs);
ClearCollect(
??ReturnedPokemonAbilities,
??ForAll(
????Table(ParseJSON(ReturnedPokemon).abilities),
????{?
?????Name: Substitute(Upper(Text(Value.ability.name)),"-", " ")?
???}??
 )
);
ClearCollect(??
ReturnedPokemonMoves,
??ForAll(
????Table(ParseJSON(ReturnedPokemon).moves),
????{??????Name: Upper(Text(Value.move.name))
????}
??)
);
ClearCollect(
??ReturnedPokemonStats,
??ForAll(
????Table(ParseJSON(ReturnedPokemon).stats),
????{
??????StatValue: Value(Value.base_stat),
??????StatName: Upper(Text(Value.stat.name))????
}
)        

To summarise the above, a second flow called FindaPokémon is called, the returned object contains a name, and three further objects within this object (moves, abilities, and stats).

We write these collections to tables, that we can use later

I then added labels to display the basic details of the Pokémon (Name, Height and Weight) and galleries to display the details from moves, abilities and stats

The Result

Screenshot of returned Pokémon (Venusaur)

I hope you enjoyed this episode of What's new in Power Platform - please join us again next week where I'll be diving into another great new feature!

To keep up to date with the latest posts, please follow me or What's new in Power Platform blog

#powerplatform #powerapps #poweraddicts #lowcodenocode #WNIPP

Charlie W. White

??Highly recommended Biz Apps Talent Professional l Enabling people to think Bigger, become Better and be Bolder l ??

2 年

Sharing for all to see!!

Lewis Baybutt

Microsoft MVP BizApps & M365 ?? Enabling enterprises through Software with AI @ Avanade ?? Digital Revolution Awards UK Rising Star of the Year ?? Co-Founder Bletchley & UK AI User Groups ?? LewisDoes.Dev ??????

2 年

Awesome post Stuart!

Nati Turtledove

Currently on a LinkedIn sabbatical ???? I’ll be back soon | Building secure and scalable Power Platform Solutions | Solutions Architect | 12x Microsoft Certified | Blogger | Speaker

2 年

[{“isMVP”: “En route”}] ????

要查看或添加评论,请登录

Stuart Baxter的更多文章

  • The death of Ribbon Workbench?

    The death of Ribbon Workbench?

    Firstly, I'd like to give Scott Durow?? a huge shout out! Ribbon Workbench has been an essential tool for Model Driven…

    44 条评论
  • The recipe for a successful software project

    The recipe for a successful software project

    I recently had a conversation with Charlie W. White about different types of developers, and I wanted to expand on it a…

    1 条评论
  • What's new in Power Platform? - Ep 18

    What's new in Power Platform? - Ep 18

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    7 条评论
  • What's new in Power Platform? - Ep 17

    What's new in Power Platform? - Ep 17

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    7 条评论
  • What's new in Power Platform? - Ep 16

    What's new in Power Platform? - Ep 16

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    1 条评论
  • What's new in Power Platform? - Ep 15

    What's new in Power Platform? - Ep 15

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    1 条评论
  • What's new in Power Platform? - Ep 14

    What's new in Power Platform? - Ep 14

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    6 条评论
  • What's new in Power Platform? - Ep 13

    What's new in Power Platform? - Ep 13

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

  • What's new in Power Platform? - Ep 12

    What's new in Power Platform? - Ep 12

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

    8 条评论
  • What's new in Power Platform? - Ep 11

    What's new in Power Platform? - Ep 11

    Before diving into the new feature, I'd like to introduce myself. I am Stuart Baxter, Power Platform Solution Architect…

社区洞察

其他会员也浏览了