Lookup elements from JSON input based on condition then populate array

Here is an approach to restructure your array of objects to a metaobject.

  1. I have parsed your sample array of objects:

  2. Then initialized an array variable to collect metaobject properties which will contain objects with the 4 properties:

  3. To an "Apply to each" block, I passed the output of the "Parse JSON" action (an array of objects) and compose a property of the metaobject with a value which is an object containing the 4 properties:

  4. Use this expression to compose a property string as in your original Excel template:

concat(items('Apply_to_each')['Component or Service Number'], items('Apply_to_each')['Component or Service'])
  1. Then I appended the composed property to the array of the metaobject:

  2. Create a metaobject string using this expression (it joins the array items into one string separating them by comas and enclosing by braces):

concat('{', join(variables('objects'), ','), '}')

  1. Here's the result that the variable contains:
{"1.01Foundations/Structural components": {
    "FC": "IO-1.01",
    "OM": "IO-1.01",
    "OM10k": "IO-1.01",
    "Cap10k": "IO-1.01"
},"1.02Roofs": {
    "FC": "IO-1.02",
    "OM": "IO-1.02",
    "OM10k": "IO-1.02",
    "Cap10k": "IO-1.02"
}}
  1. Use it with your original template.

1 Like