Try this:
# just for demonstration, you would probably do json = JSON.parse(response)
json = {
"status": 200,
"data": {
"total": 251,
"alerts": [
{
"dataPoint": "x",
"ackedBy": "x",
...
For just the total:
total = json['data']['total']
For the other values you asked about:
json['data']['alerts'].each do |alerts|
# do whatever you want with these...
alerts['dataPoint']
alerts['startOn']
alerts['ackedOn']
Now the question is, what do you want to do with the results? Do you want to collect them into a new hash? The json['data']['alerts']
is an array so you have to decide how you want to collect them. You could do:
collected_alerts = { 'dataPoints' => [], 'startOns' => [], 'ackedOns' => [] }
json['data']['alerts'].each do |alerts|
collected_alerts['dataPoints'] << alerts['dataPoint']
collected_alerts['startOns'] << alerts['startOn']
collected_alerts['ackedOns'] << alerts['ackedOn']
end
Now you can get all those values in collected_alerts