A Complete Guide to Power Apps’ New User-Defined Types: Simplifying Web API Integration and JSON Parsing

Along with the User-Defined Functions (UDF) introduced in my previous article, I’d like to introduce another very useful feature: “User-Defined Types (UDT).”

*Note: The features discussed in this article are in “experimental” phase and may be subject to changes.

Initial Setup

Similar to User-Defined Functions, you need to modify settings to use User-Defined Types. Go to [Settings] → [Upcoming features] → [Experimental] → Turn ON “User-defined types” *After changing the settings, you need to save and restart Power Apps Studio.

Basic Usage

User-Defined Types can be defined within App.Formulas.

 [Type Name] := Type({property1Name:property1Type, property2Name:property2Type ...})
// Example: Creating a type "Cat" (with properties: name, age, and birthday) Cat := Type({name:Text, age:Number, birthday:Date}); 

If you want to make a property an array type, enclose the type with square brackets [].
This allows you to set arrays of the specified type as properties (like cats in a cat café)
Since it’s an array, you can display it in a gallery.

That covers the basic usage.

Now, let’s explore “what you can do with defined types.”

Use Case 1: Receiving Web API Response Using ParseJSON

The first practical application is that you can easily parse JSON (returned from Web APIs, etc.) by combining it with the ParseJSON function.
*For this example, we’ll use this “Postal Code to Address Search API”:
郵便番号検索API - zipcloud
日本郵便が公開している郵便番号データを検索する機能をRESTで提供しています。
First, create a Power Automate flow that calls the above API and returns the response as-is.
In Power Apps, assign the Power Automate flow’s return value to a variable when a button is pressed.
Let’s consider how to handle the JSON text received from this Power Automate flow (postal code API) in Power Apps.

Previous Method: ParseJSON Only

Previously, when we wanted to use JSON content in the canvas app, we had to parse it using ParseJSON as shown in the image, which was quite complicated to write.

New Method: Combining User-Defined Types with ParseJSON

With the addition of User-Defined Types, we can now pre-define the structure of JSON received from the API like this:
By combining this “JSON definition” with ParseJSON, we can easily parse JSON as shown in the image. *Specify “JSON string as the first argument” and “defined type as the second argument” in ParseJSON
Since we’ve defined the type, we can access the contents using “.” notation, making the usage expressions much simpler.

This is a very welcome addition, as previously we had to either “create a custom connector,” “parse JSON in Power Automate and respond,” or “write complex ParseJSON expressions in Power Apps.”

Use Case 2: Easy Handling of Semi-Structured Data | Implementing Inherited Table Relationships

The next application is the ability to easily handle semi-structured data.

For example, consider working with a product table like this: While common attributes like “name” and “price” can be stored as columns, it’s challenging to decide how to define product-specific attributes (such as page count for books or playing time for music).
While there are various solutions like “separating tables by category” or “adding all columns with NULL values allowed (e.g., playback time for books would be NULL),” one solution is to store semi-structured data (JSON) in a column.
This solution works extremely well with User-Defined Types. By defining Attributes for each category like this:
You can create functions that generate descriptions using product-specific attributes, as shown in the image:
On the usage side (in galleries), you can display descriptions without needing If statements.

This feature shows a lot of promise for various other use cases, making it an exciting addition alongside User-Defined Functions that we’re looking forward to exploring further.

Related Articles

Copied title and URL