使用dataweave匹配ule子4中的数组值 [英] Matching Array values in mule 4 using dataweave
本文介绍了使用dataweave匹配ule子4中的数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用dataweave从输入有效负载中匹配特定值.
I am trying to match the specific value from input payload using dataweave.
输入:
{
"drives": [{
"id": "0AEzOyzyCb7Uk9PVA",
"name": "SFJob-2020-10"
}, {
"id": "0AMEHi1wsq-8FUk9PVA",
"name": "SFJobs-2020-11"
} ],
"nextPageToken": "~!!~AI9FV7RV4uSXy20zpCBTP2LFWCXS0c"
},
{
"drives": [{
"id": "0AEz3mOyzyCb7Uk9PVA",
"name": "Dev2020-10"
}, {
"id": "0AMEHi1wsq-8FUk9PVA",
"name": "Dev2020-11"
}],
"nextPageToken": "~!!~AI9P2LFWCXS0c"
}
我如何检查"Dev2020-10"值是否是否存在.
how can i check whether value "Dev2020-10" is present or not.
我正在使用下面的代码给我错误.
i am using below code giving me error.
%dw 2.0
output application/json
---
payload.drives filter ((item, index) -> item.name == 'Dev2020-10')
预期输出:
[{
"id": "0AEz3mOyzyCb7Uk9PVA",
"name": "Dev2020-10"
}]
我该如何实现?
推荐答案
解决方案可以考虑两个步骤:
The solution can be thought of two steps:
- 将所有驱动器合并在一起以获得对象的单个数组
flatten(inputArray.drives)
- 根据搜索条件过滤新的对象数组
filter((item,index)-> item.name =="Dev2020-11")
解决方案将是这样:
%dw 2.0
output application/json
var inputArray = [
{
"drives": [{
"id": "0AEzOyzyCb7Uk9PVA",
"name": "SFJob-2020-10"
}, {
"id": "0AMEHi1wsq-8FUk9PVA",
"name": "SFJobs-2020-11"
} ],
"nextPageToken": "~!!~AI9FV7RV4uSXy20zpCBTP2LFWCXS0c"
},
{
"drives": [{
"id": "0AEz3mOyzyCb7Uk9PVA",
"name": "Dev2020-10"
}, {
"id": "0AMEHi1wsq-8FUk9PVA",
"name": "Dev2020-11"
}],
"nextPageToken": "~!!~AI9P2LFWCXS0c"
}
]
---
flatten(inputArray.drives) filter ((item, index) -> item.name == "Dev2020-11")
要了解有关展平方法的更多信息,请参阅文档:ule子4文档
To learn more about flatten method, refer the documentation : mule 4 doc
这篇关于使用dataweave匹配ule子4中的数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文