Compact syntax for multi-select-hash #19
Replies: 4 comments 2 replies
-
Should we standardize support for empty |
Beta Was this translation helpful? Give feedback.
-
Why not support multi-select-hash = "{" *( multi-select-hash-entry ) "}"
multi-select-hash-entry = identifier / keyval-expr |
Beta Was this translation helpful? Give feedback.
-
One more reason we may need to support this. When using combinations of the
Allowing |
Beta Was this translation helpful? Give feedback.
-
This looks good to me. |
Beta Was this translation helpful? Give feedback.
-
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. In addition, this JEP enables empty
multi-select-hash
and – for consistency –multi-select-list
expressions.Specification
The
multi-select-hash
production will be changed as follows:Note that an empty
multi-select-hash
becomes legal and produces an empty JSON object.search( {}, {"foo": "bar"} ) -> `{}`
For consistency, an empty
multi-select-list
is also legal and produces an empty JSON array.search( [], { "foo": "bar" } ) -> `[]`
Motivating Example
With these changes defined, the expression in the “Motivation” section can be written as:
Which evaluates to
[{"id": 1, "first": "Bill"}, {"id": 2, "first": "Larry"}]
.Compliance Tests
This JEP standardizes a syntax that was formely not valid. For this reason, one of the
syntax.json
compliance tests must be changed or removed altogether:New tests will also be added to the
multiselect.json
file.Rationale
This JEP is inspired by an idea from Dan Vanderkam.
History
{ foo }
single-keymulti-select-hash
expression.{ }
emptymulti-select-hash
expressions.Beta Was this translation helpful? Give feedback.
All reactions