azureliquidazure-logic-appsdotliquid

Liquid Template - Item ID


Can someone please assist how can I pull the itemid from the below using a liquid template?:

{
  "orders": [
    {
      "id": 3688882438313,
      "line_items": [
        {
          "id": 9698678243497
        },
        {
          "id": 9698678276265
            }
          ]
        }
      ]
    }

I can get the order id from the following template:

{     
   "Order" : [   
      {% for order in content.orders%}      
      {          
         "ID" : "{{ order.id }}",
      },  
      {% endfor %}   
   ]
}

But cannot seem to pull the item ID no matter what I try and advice would be greatly appreciated.


Solution

  • For your requirement, here provide a sample of liquid for your reference:

    {     
        "Order" : [   
            {% for order in content.orders%}      
                {          
                    "ID" : "{{ order.id }}",
                    "ItemIds": [
                        {% for item in order.line_items%}
                            {
                                "itemId": "{{item.id}}"
                            },
                        {% endfor %}
                    ]
                },  
            {% endfor %}   
        ]
    }
    

    Run the liquid above, we can get the result:

    {
      "Order": [
        {
          "ID": "3688882438313",
          "ItemIds": [
            {
              "itemId": "9698678243497"
            },
            {
              "itemId": "9698678276265"
            }
          ]
        }
      ]
    }