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 for what could be a new descendant-expression
Specification
A new descendant-expression will be added as an alternative to the expression grammar rule:
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:
{
"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:
{
"expression": ".foo",
"error": "syntax"
},
{
"expression": "foo..bar",
- "error": "syntax"
+ "result": null
},
A new file descendant.json will be added to the compliance test suite.
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 for what could be a new
descendant-expressionSpecification
A new
descendant-expressionwill be added as an alternative to theexpressiongrammar rule:A
descendant-expressionis a projection that returns an array with all the elements of the JSON input with the specified name.Examples
Given the following JSON input:
{ "name": "first", "top": { "name": "second" }, "nested": { "name": [ 1, "string", false, { "name": "third" } ] } }The following expressions are possible:
..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:
{ "expression": ".foo", "error": "syntax" }, { "expression": "foo..bar", - "error": "syntax" + "result": null },A new file
descendant.jsonwill be added to the compliance test suite.