json - Dataweave - 过滤字段值是否为空
问题描述
我读了一个包含JSON Array
这样的文件:
[
{
"example":{
"name":"edward",
"lastName":"espin"
},
"error":"That name doesn't exists"
},
{
"example":{
"name":"toretto",
"lastName":"brav"
},
"error":null
}
]
我想使用相同的格式仅将错误值不为空的记录存储在新文件中。
我使用了一个for-each
贯穿每个 JSON 并在内部运行的方法,检查该 JSON 是否没有具有空值 ( payload.error != null
) 的“错误”字段。
问题是我for-each
在 a 中使用和choice
。
预期的输出必须是:
[
{
"example":{
"name":"edward",
"lastName":"espin"
},
"error":"That name doesn't exists"
}
]
转换组件和Dataweave 2是否有更简单的方法?
解决方案
这非常简单,只需在消息转换消息处理器中使用过滤器运算符。
%dw 2.0
output application/json
---
payload filter ((item, index) -> item.error != null)
推荐阅读
- c# - 将 JSON 数据插入到动态中的字段(例如联系人中的名字)中
- c++ - 如何解决没有上下文类型信息错误的重载函数?
- html - 谷歌浏览器不显示数据列表标签
- python - 如何从浏览器测试中检索 Ping 下载和上传时间?
- sql - 解决问题时如何与group by一起做问题?
- python - 使用内联样式而不是 CSS 将 pandas DataFrame 转换为 html
- swift - Xcode 10.2 convert multiple targets to Swift 5: 尝试编译一些不属于目标的类
- ios - iOS、watchOS、tvOS 和 macOS 的通用库框架
- c# - 当我有访问令牌代码时 Authorization_RequestDenied
- rest - 对 Wiki 页面执行 PUT 请求时为空的正文内容