0

In logic apps you can simply call json(xmlStringHere) to convert your xml to json, so not sure what do we need liquid template for.

Mocas
  • 1,403
  • 13
  • 20
  • Liquid is for transforming the XML or JSON to a different structure, if you transform via an expression, you don’t get to choose the structure. You should check out a new operation in the Advanced Data Operations connector that’s coming. It allows you to transform without the need for an integration account. It’s pretty powerful too. It’s in the doco … https://www.statesolutions.com.au/xml-to-json/ … it’ll hopefully be available in the coming few weeks. – Skin Jan 10 '23 at 10:26

1 Answers1

0

Adding to what @Skin mentioned, Sure, you can directly convert XML to JSON. However, in a few cases if the data is too complex or large to handle Liquid template comes into play. Liquid templates offer the schema too along with the conversion which maps the source data to required JSON format. To be more clear below is a sample for demonstration purposes.

Below is the XML that I'm trying to map through Liquid template

<Customer>
    <Name>aaa</Name>
    <PhoneNumber>1234567890</PhoneNumber>
    <Locations>
        <Location1>Location1</Location1>
        <Location2>Location2</Location2>
    </Locations>
    <Orders>
        <Order>
            <OrderId>12345</OrderId>
            <NoOfItems>2</NoOfItems>
        </Order>
        <Order>
            <OrderId>12346</OrderId>
            <NoOfItems>5</NoOfItems>
        </Order>
    </Orders>
</Customer>

Here is the template that I'm looking for where I can retrieve the required fields which looks a bit more complex when we try to build the same using logic apps alone.

{
    "Name" : "{{content.Customer.Name}}",
    "PhoneNumber" : "{{content.Customer.PhoneNumber}}",
    "Locations": "{{ content.Customer.Locations.Location1 %}}",
    "Orders": [
        {% for order in content.Customer.Orders %}
            {
            "OrderId" : "{{order.Order.OrderId}}"
        },
      {% endfor %}
    ]
}

Below is the flow of my Logic app

enter image description here

Results

enter image description here

For more information you can refer Convert JSON and XML with Liquid templates

halfer
  • 19,824
  • 17
  • 99
  • 186
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18