Dataweave:如何连接 json 数组中某个键的值
Dataweave: How to concatenate values for a certain key in json array
我的输入是
[
{
"Id": 5,
"FirstName": "ALEX",
"LastName": "JOHNSON"
},
{
"Id": 4,
"FirstName": "BOB",
"LastName": "BROWN"
},
{
"Id": 2,
"FirstName": "JANE",
"LastName": "DOE"
},
{
"Id": 1,
"FirstName": "JOHN",
"LastName": "SMITH"
},
{
"Id": 6,
"FirstName": "JOHN",
"LastName": "WILKINS"
},
{
"Id": 3,
"FirstName": "TIMOTHY",
"LastName": "WALTERS"
}
]
我想要的输出是一个字符串,按照它们在输入中列出的顺序连接所有 FirstName 值
"ALEX, BOB, JANE, JOHN, JOHN, TIMOTHY"
我是 Dataweave 的新手,不知道该怎么做
提前致谢
一种方法是首先将每个元素映射到 FirstName 值,然后使用 joinBy() 函数将它们连接起来,用逗号分隔:
%dw 2.0
output application/json
---
payload map $.FirstName joinBy ", "
您也可以使用 reduce() 函数。
你也可以尝试使用后代选择器
%dw 2.0
output application/json
---
payload..FirstName joinBy ","
我的输入是
[
{
"Id": 5,
"FirstName": "ALEX",
"LastName": "JOHNSON"
},
{
"Id": 4,
"FirstName": "BOB",
"LastName": "BROWN"
},
{
"Id": 2,
"FirstName": "JANE",
"LastName": "DOE"
},
{
"Id": 1,
"FirstName": "JOHN",
"LastName": "SMITH"
},
{
"Id": 6,
"FirstName": "JOHN",
"LastName": "WILKINS"
},
{
"Id": 3,
"FirstName": "TIMOTHY",
"LastName": "WALTERS"
}
]
我想要的输出是一个字符串,按照它们在输入中列出的顺序连接所有 FirstName 值
"ALEX, BOB, JANE, JOHN, JOHN, TIMOTHY"
我是 Dataweave 的新手,不知道该怎么做
提前致谢
一种方法是首先将每个元素映射到 FirstName 值,然后使用 joinBy() 函数将它们连接起来,用逗号分隔:
%dw 2.0
output application/json
---
payload map $.FirstName joinBy ", "
您也可以使用 reduce() 函数。
你也可以尝试使用后代选择器
%dw 2.0
output application/json
---
payload..FirstName joinBy ","