Skip to content

Instantly share code, notes, and snippets.

@DrPsychick
Created September 2, 2018 13:52
Show Gist options
  • Save DrPsychick/4a1faa089c4bda04f1365adfdd599bac to your computer and use it in GitHub Desktop.
Save DrPsychick/4a1faa089c4bda04f1365adfdd599bac to your computer and use it in GitHub Desktop.
nested dict with lists filtering example
"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