Convert an HTML table of values into a JSON object to be manipulated with jQuery by ignoring Particular column value
For example: I have a table,
fstname lastName Age
john gobby 8
Adams mekander 10
jimmy Rumpel 11
And I need the json result as I mentioned below,
My code is as follows,
$(document).ready(function () {
$("#ConvertJsonButton").click(function () {
var myRows = [];
var headers = [];
$("#tablesort tr#datajson").each(function(index) {
if (index === 0) {
//for headers
$cells = $(this).find("td.cellClass");
headers[index] = {};
$cells.each(function (cellIndex) {
headers[cellIndex] = $(this).text();
});
}
else {
$cells = $(this).find("td.cellClass");
myRows[index] = {};
$cells.each(function (cellIndex) {
myRows[index][headers[cellIndex]] = $(this).text();
});
}
});
var myObj = {};
myObj.myrows = myRows;
alert(JSON.stringify(myObj));
});
});
I want this result:
{
"john": {
"lastName": "gobby",
"Age": "8"
},
"Adams": {
"lastName": "Mekander",
"Age": "10"
},
"jimmy": {
"lastName": "Rumpel",
"Age": "11"
},
}