Xml to Json liquid template stopped working on Azure Logic Apps

1.2k Views Asked by At

After one month of successful mapping our template gives different results with no change in the process. Xml fragment is as follows:

  <Authorisation>
    <Application>
    </Application>
    <Role>Role on</Role>
    <Role>Role two</Role>
  </Authorisation>

and the mapping:

        "roles":[
            {% JSONArrayFor userRole in authorisation where Role-%}
            {
            "role":"{{userRole}}"
            }
            {% endJSONArrayFor -%}
        ]

The Logic App used to produce proper json collection but now, all of the sudden the collection is empty.

I can see that authorisation.Role produces just first item "Role one" and autorisation.Role.size gives 11. For loop instead of JSONArrayFor read "role one" char by char.It all means that mapping only reads first role element - there is no collection

The problem is only for Xml simple type (just xml element with string value). We process complex types in the same manner and it is still ok.

Is something internal in Azure LogicApps that has changed the mapping process last month?

2

There are 2 best solutions below

0
On BEST ANSWER

It was a bug in MS and has been fixed

2
On

It seems where Role in liquid doesn't work. I'm not sure if it work in the past, but I usually convert the xml to json first and then convert json to json if I want to implement this requirement. I provide my solution below for your reference:

1. I initialize a variable named xmlString to store the same xml as your xml data. enter image description here

2. Then I initialize another variable named jsonString and input an expression into its value box (to convert the xml to json). enter image description here

3. After that, parse the jsonString by "Parse JSON" action enter image description here

4. At last, use "Transform JSON to JSON" to transform the jsonString to the format you want. enter image description here

My liquid map is:

{% assign items = content.Authorisation.Role %}
{
    "roles": [
        {%- for item in items -%}
            {
                "role": "{{item}}"
            },
        {%- endfor -%}
    ]
}

5. Run the logic app, get the result shown as below: enter image description here