[英]Dataweave - Filter if a field value is null or not
I read a file that contains a JSON Array
like this: 我读取了一个包含JSON Array
的文件,如下所示:
[
{
"example":{
"name":"edward",
"lastName":"espin"
},
"error":"That name doesn't exists"
},
{
"example":{
"name":"toretto",
"lastName":"brav"
},
"error":null
}
]
I want to store in a new file only the records which the error value is not null using the same format. 我想使用相同格式仅将错误值不为null的记录存储在新文件中。
I have used a for-each
that runs through each JSON and inside, checks if that JSON does not have the "error" field with null value ( payload.error != null
). 我使用了for-each
,它遍历每个JSON,并且在每个JSON中运行,检查JSON是否不包含具有空值的“错误”字段( payload.error != null
)。
The problem is that I use a for-each
and in a choice
. 问题是我使用for-each
和choice
。
The output expected must be: 预期的输出必须是:
[
{
"example":{
"name":"edward",
"lastName":"espin"
},
"error":"That name doesn't exists"
}
]
Is there a simpler way with a transformation component and Dataweave 2 ? 使用转换组件和Dataweave 2是否有更简单的方法?
This is quite simple just use the filter operator in a message transform message processor. 这非常简单,只需在消息转换消息处理器中使用过滤器运算符即可。
%dw 2.0
output application/json
---
payload filter ((item, index) -> item.error != null)
下面是另一种方式
payload[?($.error != null)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.