OR operator in JSONPath?

Andrew G picture Andrew G · May 27, 2014 · Viewed 18.2k times · Source

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 

Is there any way to do this?

Answer

elyas-bhy picture elyas-bhy · Aug 20, 2015

If you are using Goessner's parser, you can use the || operator within your expression as follows:

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