如何使用 Dataweave 表示此响应?
How to represent this response using Dataweave?
我的流程中有一个调用 AmericanFlights 的 HTTP 请求器API,它的原始 GET 响应是这样的:
[{
"ID": 1,
"code": "ER38sd",
"price": 400.00,
"departureDate": "2016/03/20",
"origin": "MUA",
"destination": "SFO",
"emptySeats": 0,
"plane": {
"type": "Boeing 737",
"totalSeats": 150
}
我想过滤这些记录,只显示包含目的地为 "SFO" 和 "CLE" 的航班的记录,如下所示:
{
"flight_ID": 4,
"code": "rree1000",
"destination": {
"destination": "CLE"
}
过滤目的地的其他字段,如 ID、代码,也应从响应中删除。
实现此目的的 Dataweave 代码是什么?实际的API是这样的:Original API
快速简便的方法可能是..
%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
}
}
我的流程中有一个调用 AmericanFlights 的 HTTP 请求器API,它的原始 GET 响应是这样的:
[{
"ID": 1,
"code": "ER38sd",
"price": 400.00,
"departureDate": "2016/03/20",
"origin": "MUA",
"destination": "SFO",
"emptySeats": 0,
"plane": {
"type": "Boeing 737",
"totalSeats": 150
}
我想过滤这些记录,只显示包含目的地为 "SFO" 和 "CLE" 的航班的记录,如下所示:
{
"flight_ID": 4,
"code": "rree1000",
"destination": {
"destination": "CLE"
}
过滤目的地的其他字段,如 ID、代码,也应从响应中删除。 实现此目的的 Dataweave 代码是什么?实际的API是这样的:Original API
快速简便的方法可能是..
%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
}
}