{
"oozie": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Failed ProcessHealthMonitor health check 1 times consecutively",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"host-id": "2",
"details": "Failed ProcessHealthMonitor health check 1 times consecutively",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"host-id": "4",
"details": "Failed ProcessHealthMonitor health check 1 times consecutively",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"host-id": "5",
"details": "Failed ProcessHealthMonitor health check 1 times consecutively",
"currstatus": "Warning",
"currstatusclass": "warning"
}
],
"status": [
{}
]
},
"single-namenode": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Running Service",
"currstatus": "Running",
"currstatusclass": "success"
}
],
"status": [
{}
]
},
"single-database": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Running Service",
"currstatus": "Running",
"currstatusclass": "success"
}
],
"status": [
{}
]
},
"secondarynamenode": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Running Service",
"currstatus": "Running",
"currstatusclass": "success"
}
],
"status": [
{}
]
},
"datanode": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Failed HttpHealthMonitor health check 2 times consecutively",
"currstatus": "Warning",
"currstatusclass": "warning"
}
],
"status": [
{}
]
},
"web": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Setting Master IP",
"currstatus": "Dead",
"currstatusclass": "error"
}
],
"status": [
{}
]
},
"tasktracker": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Running Service",
"currstatus": "Running",
"currstatusclass": "success"
}
],
"status": [
{}
]
},
"jobtracker": {
"admin": {},
"hosts-list": [
"1"
],
"hostsinfo": [
{
"host-id": "1",
"details": "Running Master Service",
"currstatus": "Running",
"currstatusclass": "success"
}
],
"status": [
{}
]
}
}
Ive been at it for days trying to figure this one out and I just can’t nail it. I have no control over the actual JSON object and how its output looks like. However I have an entirely different need for it that in its current structure has posed nothing but issues for me.
What I want to do preferably with jQuery is
get the names of the Main objects
Oozie, Single-namenode, single-database, secondarynamenode, etc…
and rebuild an object for storage that follows a more practical format for use.
What I would like to see in the end is a new object that looks similar to
{
"myservices":{[
{"name":"oozie", "host-id": "1", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "host-id": "2", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "host-id": "3", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "host-id": "4", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "host-id": "5", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"single-namenode", "host-id": "2", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"}
]}
My Latest failed attempt is:
$('.refreshAllb').click(function() {
var outputCon = '';
$.getJSON('services.json', function(data) {
$('#master_service_container').empty();
$.each(data, function(i, object){
$.each(object, function(property, value){
if(property == "hostsinfo")
{
$.each(value, function(propertyX, valueX){
outputCon += propertyX[valueX] +'<br>';
});
}
});
});
$('#master_service_container').html(outputCon);
});
});
As I said Im Ive been at this for days I am at my wits end, any help is greatly appreciated.
Here’s an example. Note that your required output is invalid JSON. The
myservicesproperty cannot be an object and array as in your example. It should be either an object (associative array) or a standard javascript array:Live demo.