Table-to-JSON
lightswitch05.github.io
Table-to-JSON
1–10 of 33 posts
Re: Table-to-JSON
#2Nice work!
Re: Table-to-JSON
#3Re: Table-to-JSON
#4Awesome. Something else that would be nice is to be able to go from JSON to HTML table. There are a few libraries out there that do this but none seem to be updated or recent. Any suggestions would be greatly appreciated. Nice work!
Re: Table-to-JSON
#5What if you have headings as the first column in each row? What if you have headings in the first column, and the first row?
Also, what is the use case for data overrides? In my opinion, it completely defeats the purpose when your intention is to take the contents of the table.
Re: Table-to-JSON
#6Re: Table-to-JSON
#7It's a nice start to something that looks pretty useful. There are some things to consider though: What if you have headings as the first column in each row? What if you have headings in the first column, and the first row? Also, what is the use case for data overrides? In my opinion, it completely defeats the purpose when your intention is to take the contents of the table.
var getHeadings = function(table) {
var firstRow = table.find("tr:first").first();
return notNull(opts.headings) ? opts.headings : rowValues(firstRow);
};
The code is also going to fall down if you have things like wide/high cells. But HTML tables are so flexible and so routinely abused, I guess the problem is too hard to be solved robustly with any generality.Re: Table-to-JSON
#8Would have been nice for some Google Finance data I'm scraping in python.
Re: Table-to-JSON
#9Re: Table-to-JSON
#10It's a nice start to something that looks pretty useful. There are some things to consider though: What if you have headings as the first column in each row? What if you have headings in the first column, and the first row? Also, what is the use case for data overrides? In my opinion, it completely defeats the purpose when your intention is to take the contents of the table.
It's an alternative to the Datatables plugin. All its logic works on the set of data in JSON, so it first translates an html table into JSON, then vice versa.
The cool thing about this process is, you can write your own translate step to easily work with e.g. JSON from an Ajax request. And you can write your own render step to work with e.g. a styled list instead of a table.
By default, the translate step translates an html table to a JSON object, naming the attributes by the table column headings (underscore format by default, but can be hyphenated, snake-case, or lower-case too).
[1] http://os.alfajango.com/dynatable
EDIT: If anyone is interested, the part of the plugin that essentially does the "table to JSON" part is the getFromTable function here: https://github.com/JangoSteve/jquery-dynatable/blob/master/j...
Other useful things this function does is, determines whether the data is a string, number, boolean, or date (or other user-defined type) to do proper column sorting logic, and much more.
EDIT 2: Also, I can't speak for the author of the table-to-json plugin, but for dynatable, it's useful to have data-override values for the cells for cases like when you have a date in "Jan 1, 2013" format, which is meaningless when doing filter or sorting operations on the JSON; i.e. you could use the data-override to populate the proper date format so JS knows how to process it.