Looking for your feedback on my liquid template mapping script, I cannot parse 2nd level order within in product. I am new to the syntax trying to parse as per the expected output. Looking for your suggestions on how to fix, and handle second-level repeating records.
Looking for your feedback on my liquid template mapping script, I cannot parse 2nd level order within in product. I am new to the syntax trying to parse as per the expected output. Looking for your suggestions on how to fix, and handle second-level repeating records.
Input XML
<Products>
<Product>
<productname>iPhone</productname>
<productid>EL123</productid>
<productcategory>Electronics</productcategory>
<order>
<sold_to_customer_number>33</sold_to_customer_number>
<ship_to_customer_number>1</ship_to_customer_number>
</order>
</Product>
<Product>
<productname>OnePlus</productname>
<productid>EL124</productid>
<productcategory>Electronics</productcategory>
<order>
<sold_to_customer_number>2</sold_to_customer_number>
<ship_to_customer_number>2</ship_to_customer_number>
</order>
<order>
<sold_to_customer_number>3</sold_to_customer_number>
<ship_to_customer_number>3</ship_to_customer_number>
</order>
</Product>
</Products>
Expected JSON
{
"Products": [
{
"productname": "iPhone",
"productid": "EL123",
"productcategory": "Electronics",
"order": [
{
"sold_to_customer_number": "33",
"ship_to_customer_number": "1"
}
]
},
{
"productname": "OnePlus",
"productid": "EL124",
"productcategory": "Electronics",
"order": [
{
"sold_to_customer_number": "2",
"ship_to_customer_number": "2"
},
{
"sold_to_customer_number": "3",
"ship_to_customer_number": "3"
}
]
}
]
}
Liquid Tempalte – Issue with Order to parse
{
"Products":[
{% for item in content.Products %}
{
"productname":"{{item.productname}}",
"productid":"{{item.productid}}",
"productcategory":"{{item.productcategory}}",
"order":[
{% for item in content.Products.Product %}
{
"sold_to_customer_number":"{{item.order.sold_to_customer_number}}",
"ship_to_customer_number":"{{item.order.ship_to_customer_number}}"
},
{% endfor %}
]
},
{% endfor %}
]
}
Thanks
SMSVikasK
2
Answers
Thanks for your input. It helps. I also tried something to have a working solution to continue to progress.
what you mentioned is right, I tried all options and ended up as per below to sort my issue, and it's working for me as per expected.
the below steps/solution is working as expected.
If you can’t solve your issue (I’ve tried and I can’t either) using Liquid then I’d look at using the
Advanced Data Operations
connector, it will do it for you.The only thing it doesn’t do is wrap the resulting primary array inside a
Products
property. TheCompose
step at the end does that though.You’ll also notice that I’ve changed the names of the destination properties slightly to show the distinct difference between the source and target.
This basic flow demonstrates how …
This is the resulting JSON (noting that it appears to have ordered the properties alphabetically but that shouldn’t be an issue) …