Skip to content

Instantly share code, notes, and snippets.

@iogbole
Created April 29, 2020 14:29
Show Gist options
  • Save iogbole/4c778dcadcb72b488d76b33e0d3bc820 to your computer and use it in GitHub Desktop.
Save iogbole/4c778dcadcb72b488d76b33e0d3bc820 to your computer and use it in GitHub Desktop.
function JSONProccessor {
jq '
def myMathFunc:
if (.name | test("^sum")) then
{"\(.name)": (.values | add)}
elif (.name | test("^avg|^global-avg")) then
{"\(.name)": ((.values | add) / (.values | length)) }
elif (.name | test("^max")) then
{"\(.name)": (.values | max) }
elif (.name | test("^min")) then
{"\(.name)": (.values | min) }
else
{"\(.name)": .values[]}
end;
[
.Response.stats.data[] |
.identifier.names[] as $name |
.identifier.values[] as $val |
{"\($name)": "\($val)"} + ([
.metric[] | myMathFunc
] | add)
]
' < ${1} > ${2}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment