jmespath / jmespath/jmespath.site
[Possible improvement] Auto reset projections?
- Dominant language
- Makefile
- Stars
- 61
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
While writing the issue #108, I was wondering if an improvement shouldn't be to systematically reset projections.
---
_Little background_: I came to JMESPath thanks to its usage In Ansible. Ansible uses Jinja2, which, previously, would return Python generator from filters like `map` or `select`. Because of that, if you needed to display a mapped of filtered list, you would have to explicitly cast it back as list, with a `list` filter.
e.g.
```jinja2
[1, 2, 3, 4] | select('odd') # gives you a generator object
```
versus
```jinja2
[1, 2, 3, 4] | select('odd') | list # gives you the list [1, 3]
```
Recently, Jinja decided to change that and those filters return you a list right away, so you can finally do:
```jinja2
[1, 2, 3, 4] | select('odd') # gives you the expected list [1, 3]
```
---
I am mostly asking this because I don't see any advantage to have a projection returned.
One downside, though is that on the [pipe expression](https://jmespath.org/tutorial.html#pipe-expressions), and if we have string slicing, which will be in the next JEP, we will end up with `James`, instead of `["J", "J", "J"]`.
But shouldn't this be handled by parenthesis instead of a pipe expression (which works already!)?
```none
people[*].first[0] # gives `["J", "J", "J"]`
```
```none
(people[*].first)[0] # gives `James`
```
Possibly what could make it clearer would be to force parenthesis for the first behaviour?
```none
people[*].(first[0]) # gives `["J", "J", "J"]`
```
```none
(people[*].first)[0] # gives `James`
```
```none
people[*].first[0]
## yields any sort of error, about an ambiguous notation,
## or return an opinionated or backward compatible solution of the two above?
```
---
What are your thoughts?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.