OR operator in JSONPath?

后端 未结 2 1967
后悔当初
后悔当初 2020-12-18 21:27

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

相关标签:
2条回答
  • 2020-12-18 22:07

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

    $..log[?(@.severity == 'WARN' || @.severity == 'Error')]
    
    0 讨论(0)
  • 2020-12-18 22:12

    From the JSONPath page:

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

    Try

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

    Edit: 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.

    0 讨论(0)
提交回复
热议问题