我是MuleSoft和Mule flow的新手。
我想连接fromairport
和toairport
列。结果应该在以下列中:
fromairport toairport
MUA LAX
MUA CLE
MUA SFO
.....
我正在转换以下json:
[
{
"planeType": "Boeing 787",
"code2": "0001",
"takeOffDate": "2016-01-20T00:00:00",
"code1": "rree",
"fromAirport": "MUA",
"price": 541,
"seatsAvailable": 0,
"toAirport": "LAX",
"ID": 1,
"airlineName": "American Airlines",
"totalSeats": 200
},
{
"planeType": "Boeing 747",
"code2": "0123",
"takeOffDate": "2016-01-25T00:00:00",
"code1": "eefd",
"fromAirport": "MUA",
"price": 300,
"seatsAvailable": 7,
"toAirport": "CLE",
"ID": 2,
"airlineName": "American Airlines",
"totalSeats": 345
},
{
"planeType": "Boeing 777",
"code2": "0192",
"takeOffDate": "2016-01-20T00:00:00",
"code1": "ffee",
"fromAirport": "MUA",
"price": 300,
"seatsAvailable": 0,
"toAirport": "LAX",
"ID": 3,
"airlineName": "American Airlines",
"totalSeats": 300
}
]
我认为问题表达不正确。 DataWeave中没有“列”这样的概念。有对象,数组和属性。列的等效项是对象的属性数组。您可以在输入JSON中看到相同的概念,其中planeType,code2等是“列”。
我假设您不希望此输出不是JSON或XML格式,但是您希望对其进行进一步处理,因此与该输出的最佳匹配应该是application / java。
在Mule 4.x中,DataWeave脚本为:
%dw 2.0
output application/java
---
payload map (
$.fromAirport ++ " to " ++ $.toAirport
)
更新:基于注释,我更新了脚本以返回字符串列表。每个字符串都是fromAirport属性,文字字符串“ to”和toAirport属性的串联。这两个属性均应为字符串。
输出:
["MUA to LAX", "MUA to CLE", "MUA to LAX"]