skip to Main Content

I have a Power Automate flow that parses a JSON file and at some point I want to loop through a number of array elements that have a common structure like the sample below (NOTE: every parent element "Fo…" has a different name)

enter image description here

In my Power Automate flow there are several steps that extract only the part of the whole JSON file that contains the above structure elements. Using the xpath method I save the output to the variable varXML and I loop through its contents

enter image description here

enter image description here

Here is a more detailed view of the executed flow with input/output data

enter image description here
enter image description here

What I would like is inside the Compose – product_name step to get the value of product_name from the Compose – Add body step from each iteration of the loop. The tricky part that I am stuck here, is to use some sort of a wildcard for any "body/f***" element, in order to get to the rest of the nested elements below, like the product_name, service_name, link, etc. Thank you in advance 🙂

2

Answers


  1. Since you have it as XML already, then you don’t need to switch back to JSON.

    In your Apply to each, try the following in a Compose:

    first(xpath(items('Apply_to_each_-_varXML'), '//product_name/text()'))
    

    and

    first(xpath(items('Apply_to_each_-_varXML'), '//service_name/text()'))
    
    Login or Signup to reply.
  2. The Advanced Data Operations connector and the Json Properties To Name Value Pair Array operation will do this for you standing on its head.

    If you pass it this JSON …

    {
      "parentPropertyName1": {
        "property1": "value 1",
        "property2": "value 2",
        "property3": "value 3"
      },
      "parentPropertyName2": {
        "property1": "value 1",
        "property2": "value 2",
        "property3": "value 3"
      }
    }
    

    … it will produce this result …

    [
      {
        "propertyName": "parentPropertyName1",
        "propertyType": "Object",
        "propertyValue": [
          {
            "propertyName": "property1",
            "propertyType": "String",
            "propertyValue": "value 1"
          },
          {
            "propertyName": "property2",
            "propertyType": "String",
            "propertyValue": "value 2"
          },
          {
            "propertyName": "property3",
            "propertyType": "String",
            "propertyValue": "value 3"
          }
        ]
      },
      {
        "propertyName": "parentPropertyName2",
        "propertyType": "Object",
        "propertyValue": [
          {
            "propertyName": "property1",
            "propertyType": "String",
            "propertyValue": "value 1"
          },
          {
            "propertyName": "property2",
            "propertyType": "String",
            "propertyValue": "value 2"
          },
          {
            "propertyName": "property3",
            "propertyType": "String",
            "propertyValue": "value 3"
          }
        ]
      }
    ]
    

    … that will allow you to loop through the top level set of properties, get the name of each one and then dynamically extract the data from the original object.

    https://statesolutions.com.au/json-properties-to-name-value-pair-array/

    https://statesolutions.com.au/trial-licence-sign-up/

    Result

    Result

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search