Created
September 2, 2018 13:52
-
-
Save DrPsychick/4a1faa089c4bda04f1365adfdd599bac to your computer and use it in GitHub Desktop.
nested dict with lists filtering example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"ansible_influx_mm_backfill.results|map(attribute='json.results')|flatten|map(attribute='series')|flatten|list": [ | |
{ | |
"columns": [ | |
"time", | |
"written" | |
], | |
"name": "result", | |
"values": [ | |
[ | |
"1970-01-01T00:00:00Z", | |
1441 | |
] | |
] | |
}, | |
{ | |
"columns": [ | |
"time", | |
"written" | |
], | |
"name": "result", | |
"values": [ | |
[ | |
"1970-01-01T00:00:00Z", | |
1436 | |
] | |
] | |
}, | |
{ | |
"columns": [ | |
"time", | |
"written" | |
], | |
"name": "result", | |
"values": [ | |
[ | |
"1970-01-01T00:00:00Z", | |
1441 | |
] | |
] | |
} | |
] | |
# sum up the points written: | |
# FLATTEN always needed so "map" finds the attributes?!? | |
# cannot use "json.results.series.values" in map as results and series are lists of objects? | |
"{{ansible_influx_mm_backfill.results | |
|map(attribute='json.results')|flatten | |
|map(attribute='series')|flatten | |
|map(attribute='values')|flatten | |
|select('number')|map('int')|sum(start=0)}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment