I have a JSON as below and I want to extract data from columns and rows array from it.
{
"id":0,
"tabName":"newtab",
"columns":[
{
"id":0,
"name":"firstname",
"type":"entity",
"operator":"=",
"$$hashKey":"object:40"
},
{
"id":1,
"name":"address",
"type":"domain",
"operator":"<",
"$$hashKey":"object:50"
}
],
"rows":[
{
"0":"Adam", //this first row data corresponds to "Name" column
"1":"5432 River Drive", //this first row data corresponds to "Address" column
"$$hashKey":"object:34",
"tabId":"1122",
"description":"New Tab",
"id":1
},
{
"0":"Silver", //this 2nd row data corresponds to "Name" column
"1":"Address 2", //this 2nd row data corresponds to "Address" column
"$$hashKey":"object:53",
"tabId":"2345",
"description":"New 2nd Tab",
"id":2
}
],
"uniqueIdCounter":3
}
From the above JSON, I want to extract columns and rows values. This is just sample JSON and the actual one can have more column and rows entries.
In the columns array: id, name, type operator keys remain the same for every column entry.
In the rows array: tabid, description and id keys remain the same for every row entry.
The issue with the row array is the key values "0", "1" (that actually correspond to columns firstname & address). How to loop through this array and extract these dynamic values? By dynamic I mean if I have more than 2 rows, the keys in the rows would be "0", "1", "2" and so on for other rows.
I started with writing this loop:
var jsonColumns = JSON.parse(JSON.stringify($scope.myTable.columns));
for (var i = 0; i < jsonColumns.length; i++) {
var obj = jsonColumns[i];
//For columns data I can do obj.id, obj.name etc and works fine
}
For rows I am not sure how to proceed here:
var jsonRows = JSON.parse(JSON.stringify($scope.myTable.rows));
for (var i = 0; i < jsonRows.length; i++) {
var obj = jsonRows[i];
//How can I extract rows with keys "0", "1" where I dont know these key names in advance
}
Any inputs to this, please? Thanks