Root Reference #18
-
Root Reference
AbstractThis document proposes grammar modifications to JMESPath MotivationAs a JMESPath expression is being evaluated, the current scope changes. Once we’ve drilled down to a specific scope, there is no way, in the A common request when querying JSON objects is the ability to refer to For example, suppose we had this data:
Let’s say we wanted to get the list of cities of the state corresponding
but it is not possible to base this on a value of SpecificationThe grammar will support a new token The The This JEP introduces the following productions:
The
Motivating ExampleWith these changes defined, the expression in the “Motivation” section can be be written as:
Which evalutes to RationaleThis JEP standardizes a common request when querying JSON document as seen in existing library implementations. Some alternatives to this JEP are considered. Most notably, the Lexical Scoping proposal introduces a
Tradeoff must be considered while evaluating this JEP if Lexical Scoping were accepted. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I'd like to co-opt this proposal for the purpose of the map and reduce projections.The It would refer to the root node outside of a projection, but refer to the key or index of the current value being iterated over within a mapping projection. Additionally, within the reduce projection being proposed, The following would effectively replace the keys() function:
This would be functionally identical to the proposed items() function:
Nested projections would redefine
|
Beta Was this translation helpful? Give feedback.
-
OK! So after some discussion with @springcomp in Gitter, he wanted a more technical rationalization of how my proposed use of The intent is to provide a token that is a useful reference to a 'greater' context within the different evaluation modes (general, projection, deferred (expression-type) ). It is always a 'greater' or ancestor context rather than pointing to something adjacent or a forward reference. This is so that users, when reading a path, encounter a Not sure if this is clear, but all grey boxes are nodes regardless of shape The mapping transform is hopefully the most obvious. Reduce has no concept of keys to map to and so the 'parent' is defined a bit differently: The root reference is straight forward, and similar to reduce() points at the most relevant ancestor: I haven't finished the expression-type diagram as it is a bit more complicated as it exists in a different value space, but I wanted to get these posted before the end of today. Please let me know if there is anything unclear, I rushed this a bit. |
Beta Was this translation helpful? Give feedback.
-
@hell-racer I noticed you had an interest in this JEP. As the JEP-011 Lexical Scoping proposal is being included in the next milestone, I’m thinking out loud whether we could merge this proposal with JEP-011? As a separate proposal, this feels redundant. What do you think? |
Beta Was this translation helpful? Give feedback.
@hell-racer I noticed you had an interest in this JEP.
As the JEP-011 Lexical Scoping proposal is being included in the next milestone, I’m thinking out loud whether we could merge this proposal with JEP-011? As a separate proposal, this feels redundant.
What do you think?