0

I am using the Transform XML to JSON. This is my request body in XML

<Root>
<test>
    <column1>value1</column1>
    <column2>value2</column2>
</test>
<test>
    <column1>value1</column1>
    <column2>value2</column2>
</test>
</Root>

and this is my liquid map

{
    "test": [
        {% for data in Root.test %}
        {
            "column1": "{{data.column1}}",
            "column2": "{{data.column2}}",
        }
        {% endfor %}
    ]
}

while running the logic app i am getting parsing error:

{
  "Code": "IncorrectLiquidTransformOutputType",
  "Message": "An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: {. Path 'test[0]'"
}

But while I run the same code in the liquid sandbox is working fine. may I know? what is the issue here with logic apps.

4
  • 1
    Do you need a comma after the closing '}' inside the for loop? Commented Apr 28, 2020 at 19:36
  • I want the response to be in json. That's why tried like that Commented Apr 28, 2020 at 19:38
  • 1
    And array elements are separated by commas in JSON, which doesn't appear to be present in this example. Commented Apr 28, 2020 at 19:41
  • Hi @JeganRaj May I know if the solution I provided works ? If it helps your problem, could you please mark my answer as accepted, thanks in advance~ Commented Apr 29, 2020 at 5:26

3 Answers 3

4

I test it in my side and provide my liquid map below for your reference:

{
    "test": [
        {% for data in content.Root %}
        {
            "column1": "{{data.column1}}",
            "column2": "{{data.column2}}"
        },
        {% endfor %}
    ]
}

Run this liquid map and it works fine(shown as below screenshot) enter image description here

Hope it helps~

Sign up to request clarification or add additional context in comments.

Comments

0

I'll summarise the answers/comments already provided as I didn't see the issue when I first checked the accepted answer!

This type of error can be caused by missing out a comma at the end of a JSON object literal that you want to be repeated as elements in the array, in the transformed output.

Fails

[
    {% for data in Root.test %}
    {
        "column1": "{{data.column1}}",
        "column2": "{{data.column2}}",
    }
    {% endfor %}
]

Works

[
    {% for data in Root.test %}
    {
        "column1": "{{data.column1}}",
        "column2": "{{data.column2}}",
    },
    {% endfor %}
]

Comments

0

You should use if condition to add "," {% if forloop.last == false %},{% endif %}

{
"test": [
    {% for data in content.Root %}
    {
        "column1": "{{data.column1}}",
        "column2": "{{data.column2}}"
    }{% if forloop.last == false %},{% endif %}
    {% endfor %}
]}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.