Closed springcomp closed 2 years ago
This JEP contradicts one of the JMESPath tenets that strives to have one way to do something. On the other hand, this seems a nice and cheap way to reduce verbosity | improve readibility of a JMESPath expression.
Closed in favor of corresponding discussion.
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 renamed tomulti-select-hash-keyval
:The
multi-select-hash
production will be modified slightly to accomodate the 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.