Skip to content

Instantly share code, notes, and snippets.

@bsorrentino
Last active August 2, 2021 16:08
Show Gist options
  • Save bsorrentino/c1af3ed4bb5ede6e03c1817e3a2cd9cc to your computer and use it in GitHub Desktop.
Save bsorrentino/c1af3ed4bb5ede6e03c1817e3a2cd9cc to your computer and use it in GitHub Desktop.
Powerapps: Get field names and values from a Record ( ie. Translate a Record in a table name, value )

Abstract

This is a PowerApp Component Custom Function JsonToTable(json As String) -> Table that is able to transform a JSON Object in an equivalent PowerFx Table

Example

Considering the JSON below as input

  {
    "bsc_field1": "value1",
    "bsc_field2": "value2",
    "bsc_field3": "value3"
  }

after call of JsonToTable it will be transformed in the following PoweFx Table

Name Value
bsc_field1 value1
bsc_field2 value2
bsc_field3 value3

References

TableUtils As CanvasComponent:
JsonToTable(json As String):
json:
Default: ="Text"
ThisProperty:
Default: |
=//Table({SampleStringField: "SampleText", SampleNumberField: 10, SampleBooleanField: true})
With({
fields: Ungroup(
MatchAll(json,"("".+?""\s*:[^,}]+)").SubMatches,
"SubMatches"
)
},
ForAll(
fields,
With(Match(Value,"(?<Name>[^""]+?)""\s*:[""]?(?<Value>[^""]+)"),
{
Name:Name,
Value:Value
})
)
)
Fill: =RGBA(0, 0, 0, 0)
Height: =10
Width: =10
X: =0
Y: =0
ZIndex: =1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment