I am trying to find a nice solution, how to parse values from nested array placed at 3rd level in JSON at path aggregations.platform.buckets:
{
"aggregations": {
"platform": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 82264,
"buckets": [{
"key": 8021,
"doc_count": 29504028,
"instance_count": {
"count": 29504028,
"min": 1.0,
"max": 262082.0,
"avg": 80.40741138803149,
"sum": 2.372342517E9
}
}, {
"key": 23131,
"doc_count": 4049023,
"instance_count": {
"count": 4049023,
"min": 1.0,
"max": 55660.0,
"avg": 3.1212976562494212,
"sum": 1.2638206E7
}
}, {
"key": 5021,
"doc_count": 2356190,
"instance_count": {
"count": 2356190,
"min": 1.0,
"max": 48840.0,
"avg": 52.9123521447761,
"sum": 1.24671555E8
}
}
....
I have this code:
$.ajax({
url: esurl,
type:'post',
data: jsonQuery,
crossDomain: true,
async: false,
dataType: "text",
contentType: "application/json; charset=utf-8",
success: function(response) {
//var obj = JSON.parse(response.aggregations.platform.buckets);
var obj = JSON.stringify(response);
contentType: "application/json; charset=utf-8",
console.log("Response: " + response);
console.log("Response Obj: " + obj);
$.each(response.aggregations.platform.buckets , function(key , value){ // First Level
$.each(value.key , function(k , v ){ // The contents inside stars
console.log(v)
});
});
}
} );
I have found some inspirations here in other chats but no one is working.
When trying to parse it using JSON.parse with full path I will get error:
Cannot read properties of undefined (reading 'platform') at line var obj = JSON.parse(response.aggregations.platform.buckets);
If I use the above code I am getting same error at line $.each(response.aggregations.platform.buckets , function(key , value).
Any idea how to parse i.e. the path response.aggregations.platform.buckets.key?