本文介绍了JSONPath中的OR运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单独使用单个JSONPath表达式,是否可以执行某种"OR"或"||"操作员.例如,这两个JSONPath布尔表达式可用于检查日志JSON文件的严重性:

Using a single JSONPath expression alone, is it possible to do some kind of 'OR' or '||' operator. For example, these two JSONPath boolean expressions work to check the severity of a log JSON file:

$..log[?(@.severity == 'WARN')]

$..log[?(@.severity == 'Error')]

但是我想在逻辑上做类似的事情:

But I'd like to do something logically similar to:

$..log[?(@.severity == 'WARN' or @.severity == 'Error')] //this is not correct 

有什么办法吗?

推荐答案

来自 JSONPath页面:

[,]-XPath中的联合运算符导致节点集的组合. JSONPath允许将备用名称或数组索引作为一组.

[,] - Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.

尝试

$..log[?(@.severity == 'WARN'), ?(@.severity == 'Error')]

似乎有一个未解决的问题用于逻辑AND和OR运算符,其中它们指出JSONPath 尚不支持.

Looks like there is an open issue for logical AND and OR operators in which they state that the operators are not yet supported by JSONPath.

这篇关于JSONPath中的OR运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 09:51