While working on parsing some JSON objects with non-uniform names and quantities that needed to be tallied, I found myself in need of a hash table / dictionary. After a bit of research I settled on the setProperty approach:
Initialization
Variable ObjItems = {}
Variable ArrayObjItemsKeys = []
1. Compose Deployed Equipment Property Key
Action: Compose
Input:
replace(toLower(concat(body('Parse_JSON_from_Deployed_Equipment')?['Item'],';',coalesce(body('Parse_JSON_from_Deployed_Equipment')?['ItemState'],''))), '.', '_')
Concatenate two fields together to make the property key, case-insensitive. The replace function ensures the invalid period character is not used.
2. Compose Deployed Equipment Updated Nested Object
Action: Compose
Input:
{
"ItemName": "@{body('Parse_JSON_from_Deployed_Equipment')?['Item']}",
"ItemState": "@{body('Parse_JSON_from_Deployed_Equipment')?['ItemState']}",
"EquipmentType": "@{body('Parse_JSON_from_Deployed_Equipment')?['EquipmentType']}",
"Quantity": @{add(coalesce(variables('ObjItems')?[outputs('Compose_Deployed_Equipment_Property_Key')]?['Quantity'], 0),body('Parse_JSON_from_Deployed_Equipment')?['Quantity'])},
"CustomerCharge": @{coalesce(body('Parse_JSON_from_Deployed_Equipment')?['Customer_Charge'], 0)},
"Cost": @{coalesce(body('Parse_JSON_from_Deployed_Equipment')?['Cost'], 0)}
}
Include the values from the parsed JSON data, adding the quantity to the existing object if it already exists. The result is stored in the Compose action's output as a JSON object.
3. Compose Deployed Equipment Updated ObjItems
Action: Compose
Input:
setProperty(variables('ObjItems'), outputs('Compose_Deployed_Equipment_Property_Key'), outputs('Compose_Deployed_Equipment_Updated_Nested_Object'))Call setProperty to generate a new updated JSON object.
4. Set variable ObjItems for Deployed Equipment
Action: Set variable
Input:
outputs('Compose_Deployed_Equipment_Updated_ObjItems')Update the ObjItems variable with the updated nested object from the setProperty call.
5a. If New ObjItems Key from Deployed Equipment
Action: Condition
Input:
contains(variables('ArrayObjCountsKeys'), outputs('Compose_Deployed_Equipment_Property_Key')) is equal to false
5b. Append new key to ArrayObjItemsKeys for Deployed Equipment
Action: Append Array Variable
Input:
outputs('Compose_Deployed_Equipment_Property_Key')Appends the new key to the array of keys if it doesn't already exist. This allows looping over the keys.
Most of these steps could technically be combined into one call, but it can be nice for debugging to have them separated.
The downside to this approach is that any loops setting the object variable cannot have parallelism. In the loop settings, Concurrency Control must be enabled with the Degree of Parallelism set to 1. This can significantly increase the flow duration depending on the number of objects that need to be parsed.
Hopefully one day we'll get a more proper way of dealing with dictionaries in Power Automate online, but this way works for now.
Any suggestions for a more efficient way of handling dictionaries in PA Online would be welcome.

Report
All responses (
Answers (