parsing JSON into a table

by Alex Azuero

HTML

<body onLoad="buildHtmlTable()">
<table id="excelDataTable" border="1">
 </table>
</body>

CSS

th {
    font-weight : bold
}

JavaScript

var returnedList = {
    rows: [{
        "cartodb_id": "1",
            "the_geom": "",
            "the_geom_webmercator": "",
            "x": "93",
            "y": "12",
            "name": "",
            "place": "village",
            "addr_city": "",
            "addr_house": "",
            "addr_flats": "",
            "addr_postc": ""
    }, {
        "cartodb_id": "2",
            "the_geom": "",
            "the_geom_webmercator": "",
            "x": "94",
            "y": "25",
            "name": "Manipur",
            "place": "state",
            "addr_city": "",
            "addr_house": "",
            "addr_flats": "",
            "addr_postc": ""
    }, {
        "cartodb_id": "3",
            "the_geom": "",
            "the_geom_webmercator": "",
            "x": "95",
            "y": "28",
            "name": "Damroh",
            "place": "village",
            "addr_city": "",
            "addr_house": "",
            "addr_flats": "",
            "addr_postc": ""
    }, {
        "cartodb_id": "4",
            "the_geom": "",
            "the_geom_webmercator": "",
            "x": "95.5",
            "y": "18.5",
            "name": "Paundge",
            "place": "town",
            "addr_city": "",
            "addr_house": "",
            "addr_flats": "",
            "addr_postc": ""
    }]
};

var myList = returnedList.rows;

// Builds the HTML Table out of myList json data from Ivy restful service.
function buildHtmlTable() {
    var columns = addAllColumnHeaders(myList);

    for (var i = 0; i < myList.length; i++) {
        var row$ = $('<tr/>');
        for (var colIndex = 0; colIndex < columns.length; colIndex++) {
            var cellValue = myList[i][columns[colIndex]];

            if (cellValue == null) {
                cellValue = "";
            }

            row$.append($('<td/>').html(cellValue));
        }
        $("#excelDataTable").append(row$);
    }
}

// Adds a header row to the table and returns the set...