Reputation: 25
I have a HTTP requester in my flow which calls AmericanFlightsAPI, its original GET response is like this:
[{
"ID": 1,
"code": "ER38sd",
"price": 400.00,
"departureDate": "2016/03/20",
"origin": "MUA",
"destination": "SFO",
"emptySeats": 0,
"plane": {
"type": "Boeing 737",
"totalSeats": 150
}
I want to filter these records and show only records containing flights having destination "SFO" and "CLE", like this:
{
"flight_ID": 4,
"code": "rree1000",
"destination": {
"destination": "CLE"
}
Other fields for the filtered destination like ID, Code should also be removed from the response. What is the Dataweave code to achieve this? Actual API is like this: Original API
Upvotes: 2
Views: 58
Reputation: 4303
Quick and easy way could be ..
%dw 2.0
output application/json
---
payload filter ((value, index) -> (value.destination == 'SFO' or value.destination == 'CLE')) map {
"flight_ID" : $.ID,
"code": $.code,
"destination": {
"destination": $.destination
}
}
Upvotes: 3