This should get you what you need:
<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
function CreateJson() {
var myRows = [];
var $headers = $("thead tr").find("td");
var $rows = $("tbody tr").each(function(index) {
$cells = $(this).find("td");
myRows[index] = {};
$cells.each(function(cellIndex) {
myRows[index][$($headers[cellIndex]).html()] = $(this).html();
});
});
var myObj = {};
myObj.myrows = myRows;
alert(JSON.stringify(myObj));
}
$().ready(function() {
$("#btnTableToJson").click(function() {
CreateJson();
});
});
</script>
<style>
</style>
<html>
<body>
<table id="myTable">
<thead>
<tr><td>Name</td><td>Gender</td></tr>
</thead>
<tbody>
<tr><td>Mary Jane</td><td>female</td></tr>
<tr><td>Peter Parker</td><td>Male</td></tr>
</tbody>
</table>
<input id="btnTableToJson" type="button" value="To JSON" />
</body>
</html>