How to Transform from xml to json in Azure Logic apps using Liquid with duplicated element not in array

132 views Asked by At

How to get values from xml where objects are duplicated and names of these objects are the same: Here is sample XML

<Customer>
               <active>true</active>
               <countrycode>SE</countrycode>
               <customerstatus>
                  <customerstatusid>20</customerstatusid>
                  <customerstatusname>Active</customerstatusname>
               </customerstatus>
               <relatedcompany>
                  <active>true</active>
                  <createdby>Jeremy</createdby>
                  <createddatetime>Jan  9 2015  3:37PM</createddatetime>
                  <modifiedby>Samoson</modifiedby>
                  <modifieddatetime>Jan  9 2015  3:37PM</modifieddatetime>
                  <relatedncompanyid>0070</relatedncompanyid>
                  <relationshiptype>EXT</relationshiptype>
               </relatedcompany>
               <relatedcompany>
                  <active>true</active>
                  <createdby>joker</createdby>
                  <createddatetime>Dec 30 2015 11:43AM</createddatetime>
                  <modifiedby>Gorge</modifiedby>
                  <modifieddatetime>Dec 30 2015 11:43AM</modifieddatetime>
                  <relatedncompanyid>2500</relatedncompanyid>
                  <relationshiptype>EXT</relationshiptype>
               </relatedcompany>
            </Customer>

I cannot change that xml, so I am struggling with liquid templates on getting the values My current solution is:

"RelatedCompanies": 
        {
            {% for customer in content.customers %}
                Id" : "{{customer.relatedcompany.relatedncccompanyid}}"
            {% endfor %}
        }

But it gets only the first value, so how can I get all the values no matter how many of them in the xml

1

There are 1 answers

0
SwethaKandikonda On

After reproducing from my end, I could get this work after using the below liquid template.

{
     "relatedcompany": [
      {% for customer in content.Customer %}
        {
                "relatedncompanyid" : "{{customer.relatedcompany.relatedncompanyid}}"
        },
      {% endfor %}
    ]
}

RESULTS:

enter image description here