jmespath / jmespath/jmespath.py

treat tuples as lists

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

Description

```
import jmespath

a_work = [[{"a": 1}, {"b": 2}]]

a_not_work = list(zip([{"a": 1}], [{"b": 2}])) # jmespath cannot be applied to zipped result
assert a_not_work == [({"a": 1}, {"b": 2})] # since zipped result creates tuples instead of arayes

jpath = '[*].{s: [0], t: [1]}'

res_work = jmespath.search(jpath, a_work)
res_not_work = jmespath.search(jpath, a_not_work)

print("works as expected\n", f"input: {a_work}, output: {res_work}")
print("doesn't work as expected\n", f"input: {a_not_work}, output: {res_not_work}")
```
the code above will print the following results:
```
works as expected
input: [[{'a': 1}, {'b': 2}]], output: [{'s': {'a': 1}, 't': {'b': 2}}]
doesn't work as expected
input: [({'a': 1}, {'b': 2})], output: [{'s': None, 't': None}]
```
It would be great if tuples were treated as lists. It would allow to apply `jmespath` dirrectly to `list(zip(..))` results.

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.