jmespath / jmespath/jmespath.jep

[Initial Feedback] Recursive Tree Traversal

Open
#31 3 comments 9 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
10
Forks
3
PR merge metrics
No merged PRs in 30d

Description

A very useful feature of XSLT is to supports recursive tree traversal using XPath.
I believe such a feature would be a great addition to JMESPath.

I have drafted [a very ugly working prototype](https://github.com/jmespath-community/typescript-jmespath/tree/descendant) for what could be a new `descendant-expression`

# Specification

A new `descendant-expression` will be added as an alternative to the `expression` grammar rule:

```abnf
descendant = ".." identifier
descendant-expression = ( expression ) 1*( descendant )

expression =/ descendant-expression
```

A `descendant-expression` is a projection that returns an array with all the elements of the JSON input with the specified name.

## Examples

Given the following JSON input:

```json
{
"name": "first",
"top": { "name": "second" },
"nested": {
"name": [
1, "string", false,
{ "name": "third" }
]
}
}
```

The following expressions are possible:

|Expression|Result
|---|---
| `` ..name `` | `` ["first","second",[1,"string",false,{"name":"third"}],"third"] ``
| `` ..name.length(@) `` | `` [5, 6, 4, 5] ``
| `` ..name..name `` | `` ["third"] ``

## 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:

```patch
{
"expression": ".foo",
"error": "syntax"
},
{
"expression": "foo..bar",
- "error": "syntax"
+ "result": null
},
```

A new file `descendant.json` will be added to the compliance test suite.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.