jmespath / jmespath/jmespath.py

Why are literals left stripped?

Open
#212 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.4k
Forks
212
PR merge metrics
No merged PRs in 30d

Description

I was confused by the behaviour of the following:

```json
{
"locations": [
{"name": "Seattle", "state": "WA"},
{"name": "New York", "state": "NY"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]
}
```
when queried with the following JMESPath expression:

```
locations[].{"CityState": join(` - `, [name, state])}
```

outputs the following:

```json
[
{
"CityState": "Seattle- WA"
},
{
"CityState": "New York- NY"
},
{
"CityState": "Bellevue- WA"
},
{
"CityState": "Olympia- WA"
}
]
```

Note that this also occurs on the jmespath.org website so is presumably not just a Python implementation issue.

I noticed https://github.com/jmespath/jmespath.py/commit/4c87771b8d3bc88efd945943b5438ea28603e054#diff-ff12e4d40b1d1e1df346464bf6958de94c760d06acc3fce591b6ccf94e3b9449R137 adding the `lstrip` here but there's no explanation as to why that I can see and I can't see anything in the spec. I also didn't see anything jump out at me from a very quick look at [the Go implementation](https://github.com/jmespath/go-jmespath) but it's also a bit trickier to follow there.

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.