简体   繁体   中英

In Azure Logic apps, what is/are the advantage(s) of using a liquid template to convert xml?

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.

Adding to what @Skin mentioned, Sure, you can directly convert xml to Json, However in 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

在此处输入图像描述

RESULTS:

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM