Parsing json array in liquid template

siva pokuri 21 Reputation points
2024-09-28T23:25:25.1566667+00:00

I have been facing issues with the looping to iterate through the JSON array and create XMLHere is my sample -

{ "userPriority": "Medium", "fileAttachment": [{ "fileExt": "", "fileName": "", "fileBase64": "" }] }, "sharedList": { "contact": [ { "userId": "pokuri" }, { "userId": "sam," } ] } } Here is the policy -

<SharedList>
{% for contact in body.Document.SharedList.Contact %} <Contact>{% if contact.userId %} <UserId>{{ contact.UserId }}</UserId> {% else %} <UserId>Empty</UserId> {% endif %} </Contact> {% endfor %} </SharedList>

Here is my liquid template transformation for Azure APIM policy. However, in the trace, I see that the policy below does not read array attributes.

Please let me know if I have to correct anything in the policy.

Thanks

Siva Pokuri.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,117 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.