如何在Mule DataWeave中过滤JSON数组 [英] How to filter an array of JSON in Mule DataWeave
问题描述
我有这样的JSON:
{
"dcsId": "1184001100000000517",
"marketCode": "US",
"languageCode": "en-US",
"profile": {
"base": {
"username": "arunima27",
"activeInd": "R",
"phone": [
{
"activeInd": "Y",
"type": "mobile",
"primaryInd": "Y",
"number": "2234566788"
},
{
"activeInd": "N",
"type": "mobile",
"primaryInd": "N",
"number": ""
}
]
}
}
}
从此输入JSON中,我们需要提取有效负载.profile.base.phone.number,其中有效负载.profile.base.phone.type =="mobile"和有效负载.profile.base.phone.activeInd =="Y".实际上,我们需要遍历JSON数组(payload.profile.base.* phone),并仅获取处于活动状态并且类别/类型为移动电话的电话号码.
From this input JSON we need to extract the payload.profile.base.phone.number where the payload.profile.base.phone.type == "mobile" and payload.profile.base.phone.activeInd == "Y". Actually we need to loop through the JSON array (payload.profile.base.*phone) and get only the phone numbers which are active and having the category / type as mobile.
我们需要如下所示的输出:
We need the output like below :
{
"dcsId": "1184001100000000517",
"marketCode": "US",
"languageCode": "en-US",
"username" : "arunima27",
"phoneNumber" : "2234566788"
}
在对"phoneNumber"输出变量进行此转换时,我们面临问题.
We are facing problem in doing this transformation for the "phoneNumber" output variable.
推荐答案
这已解决了问题.
{(payload.profile.base.phone过滤器($ .activeInd =="Y"和$ .primaryInd =="Y"))}.数字默认值"
{(payload.profile.base.phone filter ($.activeInd == "Y" and $.primaryInd== "Y"))}.number default ""
这篇关于如何在Mule DataWeave中过滤JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!