Allow dot notation without root in Proposal A
glyn opened this issue ยท 9 comments
Many of the implementations allow eliding the dot where a dot child appears at the start of the path. See https://cburgmer.github.io/json-path-comparison/results/dot_notation_without_root.html.
This seems like reasonable syntactic sugar and I'd like it to be considered for Proposal A. If this proposal is rejected, it would be great to document the rational.
I must admit with Proposal A so far I've been conservative and restrictive. While this might make it easier for implementers, it does not favour the user. So, I'm happy to open up a little.
Dot child without the root so far is the only case I could come up with as a short form. As such I feel introducing a single exception might provide more headache than help. If we see other short forms, that concern would be void though. Do we have others?
Perhaps ..name
should be regarded as a contracted form of ...name
? I know we probably want to avoid the long form, but the short form could be expressed as a combination of ..
and a dot child with elided dot.
Here is k8s dialect of JsonPath, and it oficially allows to omit root (k8s uses exponent-io/jsonpath - seems we don't have it in the table yet).
As for me, root can be easily omitted in outer expressions ($.foo
-> .foo
), but that may become confusing in filters ($.foo[?(@.bar==$.baz)]
-> .foo[?(@.bar==.baz)]
? Or should we omit most commonly used @
: .foo[?(.bar==$.baz)]
?). Too many defaults may cause more problems than solve.
The OP was about eliding the dot from a dot child at the start of a JSONPath and assumed, perhaps incorrectly, that the root ($
) could already be elided at the start of a JSONPath. I think it should certainly be ok to omit both at the start of a JSONPath, but I think it's too confusing and error prone to allow either (or indeed @
s) to be omitted within filter expressions.
I think that make $
optional could cause more problem then solve, it could make expression more confuse, my personal preference is to maintain $
required.
Here is k8s dialect of JsonPath, and it oficially allows to omit root (k8s uses exponent-io/jsonpath - seems we don't have it in the table yet).
Where is exponent-io/jsonpath
used by Kubernetes? I was under the impression that kubectl uses k8s client jsonpath, but I may be wrong.
(I spent half an hour a while back trying to add the k8s client jsonpath to the table, but I lost the will to live trying to suss out the usages of interface {}
.)
Where is exponent-io/jsonpath used by Kubernetes?
I've just looked into it's go.mod
without further investigations, so I may be wrong, too.
As far as kubectl is concerned,exponent-io/jsonpath
seems to be used only during schema validation. A recent PR modifies the JSONPath behaviour of kubectl by changing k8s client jsonpath. Confusing, eh?