Slackbot
02/01/2024, 1:01 AMLee Turner
02/01/2024, 9:19 AM#each
handlebars element that might be what you are looking for. For example, with a request payload like this:
{
"source": "Web",
"orders": [
{
"id": "Order1",
"status": "In Progress"
},
{
"id": "Order2",
"status": "In Progress"
},
{
"id": "Order3",
"status": "In Progress"
}
]
}
You can write a response body like this:
{
"user": "User1",
"orders": [
{{#each (jsonPath request.body '$.orders') as |order|}}
{
"id": "{{order.id}}",
"status": "In Progress",
"shipping": "Pending"
} {{#not @last}},{{/not}}
{{/each}}
]
}
In the example above there is also the #not
element to make sure we are not on the last element in the #each
loop. This allows us to add the ,
to make it valid json.Lee Turner
02/01/2024, 9:21 AMLee Turner
02/01/2024, 9:23 AMcurl -X GET --location "<http://localhost:8080/orders>" \
-H "Content-Type: application/json" \
-d '{
"source": "Web",
"orders": [
{
"id": "Order1",
"status": "In Progress"
},
{
"id": "Order2",
"status": "In Progress"
},
{
"id": "Order3",
"status": "In Progress"
}
]
}'
Bin He
02/01/2024, 6:31 PM