Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have JSON data in the following format :

[
{
    "_index": "servers",
    "_id": "server1",
    "_score": 1,
    "_source": {
        "list": {
            "key1": {
                "c1": {
                    "check_status": "PASSED",
                    "check_name": "c1",
                    "error_msg": "NOERRORS",
                    "check_state": "OK"
                },
                "c2": {
                    "check_status": "PASSED",
                    "check_name": "c2",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            },
            "key2": {
                "c11": {
                    "check_status": "PASSED",
                    "check_name": "c11",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                },
                "c22": {
                    "check_status": "PASSED",
                    "check_name": "c22",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            }
        },
        "Date Universal": "2015-10-19T10:14:03Z",
        "SERVER EXISTENCE": "active"
    }
},
{
    "_index": "servers",
    "_id": "server2",
    "_score": 1,
    "_source": {
        "list": {
            "key1": {
                "c1": {
                    "check_status": "PASSED",
                    "check_name": "c1",
                    "error_msg": "NOERRORS",
                    "check_state": "OK"
                },
                "c2": {
                    "check_status": "PASSED",
                    "check_name": "c2",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            },
            "key2": {
                "c11": {
                    "check_status": "PASSED",
                    "check_name": "c11",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                },
                "c22": {
                    "check_status": "PASSED",
                    "check_name": "c22",
                    "error_msg": "NO ERRORS",
                    "check_state": "OK"
                }
            }
        },
        "Date Universal": "2015-10-19T10:14:03Z",
        "SERVER EXISTENCE": "active"
    }
}

]

The html table im looking for should have a single record for each server and it should show all the errors if exists for the particular server in the same row of the table.

I created a JSfiddle for the code reference herethis fiddle is not the exact script. I can pull servername and other info out to table. but looping into checks and finding out all the failed checks is what im finding hard. can someone please help me out??

Im looking for a fiddle output showing iteration of nested JSON objects for each server and printing only the failed checks and associated errors as output in a table. there are 1k servers and each has key1 checks 20 and key2 checks 20. The controller code is like this

var app=angular.module('angmod', []);
app.controller('ctrl1',function($scope,$http,$interval){
load_data();
$interval(function(){
load_data();
},5000);
function load_data(){
   data=[{
"_index":"servers",
"_id":"server1",
"_score":1,
"_source":{
"list":{
"key1":{"c1"{"check_status":"PASSED","check_name":"c1","error_msg":"NOERRORS","check_state":"OK"},"c2":{"check_status":"PASSED","check_name":"c2","error_msg":"NO ERRORS","check_state":"OK"}},

"key2":{"c11":{"check_status":"PASSED","check_name":"c11","error_msg":"NO ERRORS","check_state":"OK"},"c22":{"check_status":"PASSED","check_name":"c22","error_msg":"NO ERRORS","check_state":"OK"}}
},

"Date Universal":"2015-10-19T10:14:03Z",
"SERVER EXISTENCE":"active"}
}],

"Date Universal":"2015-10-19T10:14:03Z",
"SERVER EXISTENCE":"active"}
},{"_index":"servers",

"_id":"server2",
"_score":1,
"_source":{
"list":{
"key1":{"c1"{"check_status":"PASSED","check_name":"c1","error_msg":"NOERRORS","check_state":"OK"},"c2":{"check_status":"PASSED","check_name":"c2","error_msg":"NO ERRORS","check_state":"OK"}},

"key2":{"c11":{"check_status":"PASSED","check_name":"c11","error_msg":"NO ERRORS","check_state":"OK"},"c22":{"check_status":"PASSED","check_name":"c22","error_msg":"NO ERRORS","check_state":"OK"}}
},

"Date Universal":"2015-10-19T10:14:03Z",
"SERVER EXISTENCE":"active"}
}]
  }]
$scope.qwe=data;
});
};
})

can someone explain the logic???

share|improve this question
    
Your json is invalid! – Daniel Cheng Oct 19 '15 at 14:04
    
explain what logic? You need to pre-filter your data using javascript array and object methods. Data provided has syntax errors in it – charlietfl Oct 19 '15 at 14:11
    
You mean the JSON data has errors?? – sasikant Oct 19 '15 at 14:17
    
Put your json in jsonlint.com and you'll know. – Daniel Cheng Oct 19 '15 at 14:20
    
hi please find the edited JSON document. – sasikant Oct 19 '15 at 15:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.