Consider implementing ES6 compact-style multi-select-hash like {x, y}
#13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Compact syntax for multi-select-hash
Abstract
This JEP proposes a grammar modification to support ES6-style compact
multi-select-hash
constructs.Motivation
Consider the following JSON document:
Let’s say we wanted to return a hash containing
id
s andfirst
names.This is currently possible using the following syntax:
Since
{x:x, y:y}
is such a common pattern, ES6 introduced compact object literal notation to simplify this. In ES6,{x,y}
is equivalent to{x:x, y:y}
.This JEP supports this syntax to make JMESPath usage slightly less verbose.
Specification
What is currently the
multi-select-hash
production will be renamedto
multi-select-hash-keyval
:The
multi-select-hash
production will be modified slightly to accomodatethe syntax changes:
The new
multi-select-hash-key
production is defined like so:Here is the full update to the grammar:
Motivating Example
With these changes defined, the expression in the “Motivation” section can be
be written as:
Which evaluates to
[{"id": 1, "first": "Bill"}, {"id": 2, "first": "Larry"}]
.Rationale
This JEP is inspired by an idea from Dan Vanderkam.