Power Apps Detailed usage of ParseJSON function|How to convert HTTP request response

The ParseJSON function is now GA, so I looked up how to use it.

スポンサーリンク

ParseJSON function/h2> The ParseJSON function converts (parses) text in JSON format into data that can be used in Power Apps. Click here for the official ParseJSON function - Power PlatformReference information including syntax and examples for the ParseJSON function.learn.microsoft.com JSON is a data format that can represent a variety of information in a single text, and is used for various purposes such as API return values and CosmosDB. Here is a JSON representation of our cat’s information. { "Age": 3, "Name": "こつぶ", "Species": "スコティッシュフォールド", "VaccinationHistory": [ { "date": "2023-06-01", "name": "3種混合" }, { "date": "2022-06-01", "name": "3種混合" }, { "date": "2021-06-01", "name": "3種混合" } ] } Untyped object

The ParseJSON function returns data of type “Untyped object” as the return value.

Untyped object is a data type that contains data that the Power Apps side cannot determine what kind of data type it is.

So, the value obtained by ParseJSON must be converted to the Power Apps data type using a function to make it usable,

So, the values obtained with ParseJSON were supposed to be usable without converting them to Power Apps data types using functions, but it seems that simple data such as strings and numbers can now be inferred and used on the Power Apps side.

*I’m pretty sure you couldn’t do that during the preview.

Thus, data of numeric type and the like can be used directly without the need for conversion.

However, it is more helpful to the code reader if you call the conversion functions properly, so we will introduce a few typical conversion functions.

Text

Use the Text function to change data acquired with ParseJSON into a text type.

Number

Use the Value function to convert a value obtained with ParseJSON to a type of Number.

Date

If you want to convert to Date type, use DateValue function,
To convert to DateTime type, use the DateTimeValue function.
※String must be in ISO8601 format
ISO 8601 - Wikipedia

Record

For Record type (object), you can convert the acquired properties by connecting them with dots “. to connect the acquired properties and perform the conversion.

Array

Array type data can be converted to table type data that can be handled by Power Apps using the ForAll function, as shown in the figure below.

Parse JSON returned by HTTP request with Power Apps

First, we created a simple Power Automate that simply sends an HTTP request to get an address and returns JSON of the return value.
Then call the Power Automate and put the return value into a variable.
Here is the returned JSON.
Using the ParseJSON function on this JSON, the address can be obtained.

So ParseJSON is very useful, and its use is likely to increase in the future.

コメント

Copied title and URL