0

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???

7
  • Your json is invalid! Commented Oct 19, 2015 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 Commented Oct 19, 2015 at 14:11
  • You mean the JSON data has errors?? Commented Oct 19, 2015 at 14:17
  • Put your json in jsonlint.com and you'll know. Commented Oct 19, 2015 at 14:20
  • hi please find the edited JSON document. Commented Oct 19, 2015 at 15:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.