Similar question, my json is e.g.,
{
"alertInstanceId": "05985927-ab93-4933-9d62-51744d64af0e",
"alertName": "403 and 404 Not Found Test Webhook Test",
"org": "amer-demo13",
"description": "403 and 404 Not Found Test with Webhook",
"alertId": "6f8ff505-16db-11ea-ad50-42010a850821",
"alertTime": "2020-10-05T16:04:11Z",
"thresholdViolations": {
"0 - Count": "Duration=5 minutes Proxy=ALL Region=us-east1 Status Code=403 Trigger Value=7 Violation=sustained above 5.0",
"1 - Count": "Duration=5 minutes Proxy=ALL Region=us-east1 Status Code=404 Trigger Value=7 Violation=sustained above 5.0"
},
"thresholdViolationsFormatted": [{
"metric": "count",
"proxy": "ALL",
"region": "us-east1",
"statusCode": "403",
"comparisonType": "above",
"thresholdValue": "5.0",
"triggerValue": "7",
"duration": "5 minutes",
"violation": "sustained above 5.0"
},{
"metric": "count",
"proxy": "ALL",
"region": "us-east1",
"statusCode": "404",
"comparisonType": "above",
"thresholdValue": "5.0",
"triggerValue": "7",
"duration": "5 minutes",
"violation": "sustained above 5.0"
}],
"playbook": "TEST2: Check out the 404 playbook for test"
}
this ExtractVariable segment will give me the contents of “0 - Count”,
<JSONPath>$.thresholdViolations.0 - Count</JSONPath>
but I’d like to extract every value in thresholdViolations into a separate variable, not knowing in advance how many items are in that dict, or even what the names of each value in the dict are.
This code will give me a list of the values in thresholdViolations,
<JSONPath>$.thresholdViolations.*</JSONPath>
but then i need to extract each of the items in the list into separate variables. The reason for all of this is that eventually, I’m going to need to create a payload like this:
[{
"name" : "Count0",
"value" : "Duration=5 minutes Proxy=ALL Region=us-east1 Status Code=403 Trigger Value=7 Violation=sustained above 5.0"
},
{
"name" : "Count1",
"value" : "Duration=5 minutes Proxy=ALL Region=us-east1 Status Code=404 Trigger Value=7 Violation=sustained above 5.0"
}
]