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

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

Avoid implicitly converting NodesType to ValueType #420

Closed glyn closed 1 year ago

glyn commented 1 year ago

This implicit conversion can be surprising in some situations, so it is made explicit via the value() function.

Calling the value() function is a conscious choice, so should not be a surprise to the user.

Fixes https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base/issues/404

gregsdennis commented 1 year ago

I specifically do not like conversion functions. They are unnecessary cruft.

For the conversion from NodesType to ValueType, I'm happy forbidding it, as we have in #412. I see no reason why a multiple nodelist should ever be converted to a value, even if it happens to have zero or one node.

gregsdennis commented 1 year ago

Along with https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base/pull/412#issuecomment-1462723620, I'm going to say that I'm okay with this as long as it's not trying to address the issues that SingleNodeType is trying to address.

My only argument against value() is that it enables behavior that can be unintuitive, even if it's explicit. I don't see any reason for a multiple-nodelist to be converted into a value. No one has provided a use case for this.

This needs to be merged after #412.

glyn commented 1 year ago

Merged. See https://github.com/ietf-wg-jsonpath/draft-ietf-jsonpath-base/issues/404#issuecomment-1465175176 for the rationale behind this.