OR in JSONPath?

Using only one JSONPath expression, is it possible to do some kind of "OR" or "||" operator. For example, these two Boolean JSONPath expressions work to check the severity of the JSON log file:

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

But I would like to do something logically similar to:

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

Is there any way to do this?

+6
source share
2 answers

From the JSONPath page :

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

Try

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

Edit: There seems to be an open problem for the logical AND and OR operators in which they state that the operators are not yet installed . JSONPath is supported .

+4
source

If you use the Gessner parser, you can use the || in its expression as follows:

 $..log[?(@.severity == 'WARN' || @.severity == 'Error')] 
+6
source

Source: https://habr.com/ru/post/969927/


All Articles