I'm trying to facilitate power apps development in the grey area between professional and non-professional (aka citizen) software developers. I want to create tools that may help both types of developers creating and using PCF components or more complex traditional components, and I believe it is important that I actually use Power Platform to achieve it.
I've often encountered a need to generate Power FX code, E.g. for static menu galleries or settings for various components etc. Even though ParseJSON() and JSON() are useful in many ways, there seems to be a barrier for exporting PowerFX object notation such as the code for a table or object in an app to the user. (Essentially just removing the double quotes from field names)
I have arrived at a hack and I'm wondering if I'm missing some essential trick for this, I am interested to hear about other methods to achieve this or similar things.
One example is a configuration tool for the Creator Kit DetailsList control that takes a collection for format configuration.
Getting the JSON is simple, but translating this object into a PowerFX object notation is convoluted, the following is the formula for the Refresh buttons (lower right) OnSelect property:
With(
{
JsonPayload: JSON(
colDetailsListColumns,
JSONFormat.IndentFour
)
},
Clear(colJsonPayloadTable);
ForAll(
Split(
JsonPayload,
""
),
Collect(
colJsonPayloadTable,
{
CharNo: CountRows(colJsonPayloadTable),
Char: ThisRecord
}
)
);
ForAll(
MatchAll(
JsonPayload,
"(\"")([a-zA-Z]+)(\"":)"
) As JsonFormatFieldName,
RemoveIf(
colJsonPayloadTable,
CharNo = JsonFormatFieldName.StartMatch - 1// Relative position of the first double quote.
);
RemoveIf(
colJsonPayloadTable,
CharNo = JsonFormatFieldName.StartMatch + Len(JsonFormatFieldName.FullMatch) - 3// relative position of the second double quote
)
);
UpdateContext(
{
locDetailsListConfigurationJson: JsonPayload,
locDetailsListConfigurationPfx: Concat(
colJsonPayloadTable,
Char.Value,
""
)
}
);
Clear(colJsonPayloadTable)
);
This works perfectly for basic objects, but I suspect its not supporting complex objects and I believe its going to stall for slightly bigger objects.
I've tried other ways of using MatchAll() and Substitute() / Replace() but, I find it very difficult to debug and keep track of escaping the double quotes etc. Anyone else worked on something similar and have some suggestions on how this can be done differently?
WarrenBelz
85
Most Valuable Professional
Michael E. Gernaey
65
Super User 2025 Season 1
mmbr1606
55
Super User 2025 Season 1