Basically I want to filter a nested array of that shape:
[
[0, {…}],
[1, {…}],
…
]
this jms path expression is working on the playground:
[?@[0] > `0`]
and when run like that from an ansible playbook:
- debug: msg="{{ [[1],[2],[3],[4]] | community.general.json_query('[?@[0] > `1`]') }}"
but when done like that:
- debug: msg="{{ range(0,3) | zip(range(3,0,-1)) | community.general.json_query('[?@[0] > `1`]') }}"
it yields an empty list ([]
)
Boiling it down even more:
ansible@r2d2:~$ ansible localhost -m debug -a $'msg="{{ range(0, 3) | zip(range(3,0,-1)) | json_query(\'@[0]\') }}"'
localhost | SUCCESS => {
"msg": "(0, 3)"
}
Show that the result is some sort of tuple, which is no json data type at all. The data that I would like to filter is constructed like the above, using range
and zip
so how can make the expression work in those circumstances?
UPDATE
Going deeper on that showed that this whole problem has two causes.
{{ range(0,3) | type_debug }} => 'range'
can easily be solved by{{ range(0,3) | list | … }}
{{ [0] | list | zip([0]) | list | json_query('@[0]') | type_debug }}
=> 'tuple'
There seams to be a python solution here, but how to do that in jinja??