使用`jsonPath`筛选出具有空数组的元素的表达式 [英] Expression to filter out elements with empty arrays using `jsonPath`
本文介绍了使用`jsonPath`筛选出具有空数组的元素的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下格式的JSON有效负载:
I have a JSON payload of the form:
[
{"id": 1, "list": [1], "name":"one"},
{"id": 2, "list": [1,2], "name":"two"},
{"id": 3, "list": [], "name":"three"}
]
我想从数组中滤除元素,其中包含一个空的"list"
属性.换句话说,我想用id=3
放弃该元素,而仅在上面的示例中处理第一个和第二个元素.
And I want to filter out the element from the array the contains an empty "list"
property. In other words, I want to discard the element with id=3
and process only the first and second element in my example above.
当前,我的过滤器如下所示:
Currently, my filter looks like this:
<!-- ne == not equals -->
<int:filter id="filter"
input-channel="in"
output-channel="out"
expression="#jsonPath(payload, '$[*].list') ne '[]'"
discard-channel="consoleOutputChannel" />
但这不起作用,如何向我的expression
指示要排除具有空list
属性的元素?
But this is not working, how should I indicate to my expression
that I want to exclude elements with empty list
properties?
推荐答案
将表达式更改为:
$.[?(@.list.length()> 0)]
-
[?(<expression>)]
:过滤器表达式 -
@
:正在处理的当前节点 通过过滤谓词 -
list.length()
:list
数组的长度 [?(<expression>)]
: filter expression@
: The current node being processed by a filter predicatelist.length()
: the length oflist
array
更多详细信息,请参见 JsonPath
More detail at JsonPath
这篇关于使用`jsonPath`筛选出具有空数组的元素的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文