dataweave - dataweave fetch first char from array elements
问题描述
I am trying to see if any Types.Flag starts with 'X', if true, I need to set 'subscribed' to true.
Input:
{
"Subscribers": [{
"PhoneNumber": "9876543210",
"Types": [{
"Name": "abcd",
"Flag": "WIR"
},
{
"FilterName": "efg",
"Flag": "XNJ"
},
{
"FilterName": "hijk",
"Flag": "YIR"
}
]
},
{
"PhoneNumber": "9823456789",
"Types": [{
"FilterName": "lmn",
"Flag": "MST"
}]
}
]
}
Expected output
{
"subscriberList": [
{
"phoneNumber": "2012020004",
"subscribed": true
},
{
"phoneNumber": "2234567890",
"subscribed": false
}
]
}
Could you please suggest on how this could be achieved?
解决方案
Try this:
%dw 2.0
output application/json
import some from dw::core::Arrays
var data = {
"Subscribers": [{
"PhoneNumber": "9876543210",
"Types": [{
"Name": "abcd",
"Flag": "WIR"
},
{
"FilterName": "efg",
"Flag": "XNJ"
},
{
"FilterName": "hijk",
"Flag": "YIR"
}
]
},
{
"PhoneNumber": "9823456789",
"Types": [{
"FilterName": "lmn",
"Flag": "MST"
}]
}
]
}
---
subscriberList: data.Subscribers map {
phoneNumber: $.PhoneNumber,
subscribed: $.Types.*Flag some (e) -> e startsWith "X"
}
Here's the documentation of the functions I made use of:
推荐阅读
- javascript - 访问异步函数中的变量
- python - 如何与字典python中的其他键交换键(不与值)
- autodesk-forge - 如何从伪造查看器中获取所有数据
- javascript - 为什么 FULLCALENDAR 在 13:00(下午 1:00)之后不显示事件?
- linear-programming - 将条件约束转换为线性规划的线性约束
- java - 设置每个延迟时间
在TestNG中 - postgresql - Postgres:防止新用户在没有超级用户的情况下创建表
- git - 错误:无法打开 .git/FETCH_HEAD:错误消息
- python - 我想找到组内的最小差异并返回索引。(Python,pandas)
- javascript - 为什么不能在外面获取数据