jmespath-community / jmespath.spec

JMESPath Specification
6 stars 3 forks source link

Clarify `sub-expression` evaluation behaviour. #106

Closed springcomp closed 1 year ago

springcomp commented 1 year ago

A sub-expression is very similar to a pipe-expression with a few key differences:

However, when none of the left and right expressions involve projections, those two constructs are effectively identical. Some library implementations return different results in thoses cases.

Given those expressions do not involve any projection, they should have the same result. This calls into question which is the correct result.

Compliance tests suggests the correct result is null and not [ null ]. The canonical JavaScript implementation hosted in https://jmespath.org and https://jmespath.site agrees with this.

However, the specification calls out how a sub-expression (and thus, by extension) a pipe-expression should be implemented.

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

However, compliance tests cannot succeed by following this guideline. For instance, this compliance test looks like so:

search( foo.[a || b], {"type": "object"} ) -> null

Which evaluates to:

This PR clarifies the pseudo-code evaluation instructions for sub-expression to align with the compliance tests and the behaviour of the canonical JavaScript implementation. It changes the text to:

left-evaluation = search(left-expression, original-json-document)
if left-evaluation is `null` then result = `null`
else result = search(right-expression, left-evaluation)