[Initial Feedback] Root Node Reference
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 30/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Ambito
- compilers
Direzione di ricerca
Leggi la grammatica proposta del nodo radice e l'esempio motivante, quindi confrontali con la proposta collegata di Lexical Scoping. Poiché si tratta di una proposta di feedback iniziale senza file di implementazione né test indicati, done significa arrivare a una decisione del progetto sull'opportunità di accettare la sintassi $ e su come questa si inserisca nella specifica del linguaggio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Root Reference
I would like to submit the following proposal, so that we can access root node from anywhere.
Abstract
This document proposes grammar modifications to JMESPath
to support referring to the original input JSON document
inside an expression.
Motivation
As a JMESPath expression is being evaluated, the current scope changes.
Given a simple sub expression such as foo.bar, first the foo
expression is evaluated with the starting input JSON document, and the
result of that expression is then used as the current scope when the
bar element is evaluated.
Once we’ve drilled down to a specific scope, there is no way, in the
context of the currently evaluated expression, to refer to any
elements outside of that element.
A common request when querying JSON objects is the ability to refer to
the input JSON document.
For example, suppose we had this data:
{
"first_choice": "WA",
"states": [
{"name": "WA", "cities": ["Seattle", "Bellevue", "Olympia"]},
{"name": "CA", "cities": ["Los Angeles", "San Francisco"]},
{"name": "NY", "cities": ["New York City", "Albany"]}
]
}
Let’s say we wanted to get the list of cities of the state corresponding
to our first_choice key. We’ll make the assumption that the state
names are unique in the states list. This is currently not possible
with JMESPath. In this example we can hard code the state "WA":
states[?name==`"WA"`].cities
but it is not possible to base this on a value of first_choice, which comes from the parent element.
This JEP proposes a solution that makes this possible in JMESPath.
Specification
The grammar will support a new token $ that refers to the root of the original input JSON document.
The $ token is inspired by the JSONPath specification which has a token with the same name.
The $ token is also inspired by the XPath specification, where the / token designates the root of the original XML document.
This JEP introduces the following productions:
root-node = "$"
The expression production will also be updated like so:
expression =/ root-node
Motivating Example
With these changes defined, the expression in the “Motivation” section can be be written as:
states[?name==$.first_choice].cities[]
Which evalutes to ["Seattle", "Bellevue", "Olympia"].
Rationale
This 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 let keyword that offers a more general and flexible way to achieve the desired result. For instance, with the let keyword, the expression in the “Motivation” section can be written as:
let $root = @ in states[?name==$root.first_choice].cities[]
Although the Lexical Scoping proposal covers this case in a more generic way, using the $ root node reference provides a more succinct way to express a common case.
- Lingua principale
- Python
- Stelle
- 10
- Fork
- 3
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di jmespath/jmespath.jep
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#35 ·
-
Root node accessAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#34 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#33 ·
-
Allow string comparisonAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
jmespath/jmespath.jep#32 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
jmespath/jmespath.jep#31 · 3 commenti · 9 reazioni ·
Tutte le issue di jmespath/jmespath.jep
Issue simili
-
test_real_pandoc_failure_is_one_path_free_line fails on macOS CI with current Homebrew pandocApertabug TAG: unit tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
learningequality/ricecooker#898 ·
-
task
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
freelawproject/litigant-portal#1285 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
jmespath/jmespath.py#401 ·
-
least_squares returns a nonfinite objective for an invalid initial residualForse già presa @sylvesterkaczmarek l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
google-deepmind/mujoco#4023 ·
I maintainer di solito rispondono entro 11 giorni
-
Five Australian birds: Red-capped Parrot, Red-winged Fairywren, Gilbert’s Honeyeater, Western Spinebill, Western WattlebirdForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
arnegiacomo/fugleramme#427 ·
I maintainer di solito rispondono entro 1 giorno