Re: How to convert a table to JSON (or to Javascript array)

David Dashifen Kees
2007-06-14T01:58:05Z

Not that I''m aware of without parsing the table element using the DOM
walking functions.  Something like this might do it:

function tableToJSON(tableID) {
    var tableData = $A();
    var rows = $$("#"+tableID+" tr).each(function(row) {
       var cellData = $H(row.descendants().pluck("innerHTML"));
       tableData.push(cellData);
    });

    return tableData.toJSON();
}

But I''ve not tried it, nor am I sure that will work.

 - Dash -
phil swenson wrote:
> Is there a way to retrieve an HTML table in javascript and convert it
> to JSON using prototype?
>
> I''m stumped :(
>
> phil