ietf-wg-jsonpath / draft-ietf-jsonpath-base

Development of a JSONPath internet draft
https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/
Other
58 stars 20 forks source link

filter expression comparison behavior when local path returns no results #357

Closed gregsdennis closed 1 year ago

gregsdennis commented 1 year ago

I came across this while adding some filter cases to the CTS.

$[?@.a!=null]
[{"d": "e"}, {"a":"c", "d": "f"}]

Is {"d": "e"} selected?


Relevant text from the spec:

When a path resulting in an empty nodelist appears on either side of a comparison:

  • a comparison using the operator == yields true if and only if the comparison is between two paths each of which result in an empty nodelist.
  • a comparison using the operator < yields false.

and later

!=, <=, >, and >= are defined in terms of the other comparison operators. For any a and b:

  • The comparison a != b yields true if and only if a == b yields false.
  • The comparison a <= b yields true if and only if a < b yields true or a == b yields true.
  • The comparison a > b yields true if and only if b < a yields true.
  • The comparison a >= b yields true if and only if b < a yields true or a == b yields true.

So DNE == DNE evaluates as true, implying that

I'm not so sure about DNE != anything being true, but as long as it's well-defined, I could be okay with it.

Since DNE < 42 returns false,

Okay. I think this makes sense.

If all this is right, then my original question about {"d": "e"} would boil down to DNE != null which would evaluate to true, so it would be returned. To set up the expression so that it is not returned, it'd have to be $[?@a && @.a!=null].

Can someone verify all that, please?

glyn commented 1 year ago

Yes, I think you are interpreting the spec correctly.