jmespath / jmespath/jmespath.js

filtering flattened projection does not seem to follow projection rules

Open
#68 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
847
Forks
101
PR merge metrics
No merged PRs in 30d

Description

# Scenario
If we have an object like so:
```json
{
"persons": [
{
"name": "bob",
"addresses": [
{
"current": true,
"address": "132 Main Ave"
},
{
"current": false,
"address": "99 1st St"
}
]
},
{
"name": "linda",
"addresses": [
{
"current": true,
"address": "132 Main Ave"
},
{
"current": false,
"address": "99 1st St"
}
]
}
]
}
```
and the query:
```
persons[?name=='bob'].addresses[]
```
I get the result
```json
[
{
"current": true,
"address": "132 Main Ave"
},
{
"current": false,
"address": "99 1st St"
}
]
```
This seems to line up just fine with the documentation of [what a "projection"](https://jmespath.org/tutorial.html?highlight=projection#projections) is in JMES.
It is my understanding that Filter and Flatten are both types of projections. So if I then filter the flattened projection like so
```
persons[?name=='bob'].addresses[][?current]
```
I would expect this
```
[
{
"current": true,
"address": "132 Main Ave"
}
]
```
but instead I have to pipe the result to a filter projection in order to get this to work:
```
persons[?name=='bob'].addresses[] | [?current]
```

# Question / Issue
I would not expect that I have to first use the pipe operator in order to achieve that.
Why is it that the filter is not applied as a projection of each result of the flatten operation? Am I misunderstanding something about what is/is not a projection and how the projection algorithm is supposed to work?

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.