Updates to simplify using JSON

We’re pleased to announce some exciting updates to how makers can use untyped objects. ParseJSON() and untyped objects are very flexible, but we’ve heard your feedback that improvements are needed to require less code and make untyped objects easier to use. So today’s announcement is all about implicit type conversion, or coercion. For untyped objects it means the automatic conversion of untyped objects to the actual type required based on the context. We will do this for all simple scalar types: booleans, numbers, text, GUIDs, colors, dates and times.

Less restrictive conversion functions

Until today, Boolean(), Value() and Text() required that the underlying type of their respective parameters was actually a boolean, value or text type. If not, you would have to first convert to the underlying type, then to the desired type. For example, a JSON string of { number: "123" } has a field called “number” that is actually a text. Previously, this required you to convert number first to text, then to value: Value( Text( untyped.number ) ). Going forward, these types will convert automatically where possible, and the previous example can simple be written as Value( untyped.number ).

Function argument type coercion

We previously required makers to always explicitly convert types. To get the square root of a number coming from an untyped object, it required a formula such as Sqrt( Value( untypednumber ) ). Going forward, Power Fx will attempt to automatically convert the untyped object to the expected type of the function. So the previous example can now simply be written as Sqrt( untypednumber ). There can be some ambiguity if a function has multiple overloads with different types, in which case explicit conversion may still be required.

Operators and Untyped Objects

Additionally, you can now use operators on the untyped objects if at least one of the operands is a concrete type or if the operator implies the type. For example, untypednumber * 100 or untypedtext1 & untypedtext2.

Top-level coercion for control properties

Saving the best for last, you can now also assign untyped objects directly to a property. Much like you can specify a formula of type “number” to a label’s text property and Power Fx will coerce the number to text, you can now also assign an untyped object to a property and it will automatically convert if possible. So, you can set Label1.Text  to myjsonobject.myfield! This means you can assign a Table( untypedarray ) to a gallery and assign untyped fields to controls in your gallery without needing to convert either the full table first, or each individual field in the gallery.

graphical user interface, text, application
Expression concatenating a JSON untyped number, text and boolean into one text property, showing operators and coercion.

Final notes

Keep in mind that records or tables do not coerce. Certain functions such as ForAll(), Index(), CountRows(), First() and Last() explicitly accept untyped object arrays, but this is not a general coercion rule.

Connectors in Power Apps are also working on leveraging untyped objects for more flexible and dynamic ways to receive data. Read more on Learn.

We have a lot of ideas to improve ParseJSON() and untyped objects further, but we feel the set of features we have at this point is comprehensive and complete, and we will be able to move these features out of the experimental state soon. As always, we appreciate your feedback and look forward to hearing from you in our experimental forums.