Attempts to convert HTML tables into JSON.
Can be passed the markup for a single table as a string, a fragment of HTML or an entire page or just a URL (with an optional callback function; promises also supported).
The response is always an array. Every array entry in the response represents a table found on the page (in same the order they were found in the HTML).
This module only supports parsing basic tables with a simple horizontal set of
It can give useless results on tables that have complex structures or multiple headers (such as on both X and Y axis).
You'll need to handle things like work out which tables to parse and (in most cases) clean up the data. You might want to combine it it with modules like json2csv.
You might want to use it with a module like 'cheerio' if you want to parse specific tables identified by id or class (i.e. select them with cheerio and pass the HTML of them as a string).
// Convert an HTML blob into an array of all the tables on the pagevar tabletojson = ;var tablesAsJson = tabletojson;var firstTableAsJson = tablesAsJson0;var secondTableAsJson = tablesAsJson1;...
// Fetch a URL and parse all it's tables into JSON, using a callbackvar tabletojson = ;var url = '';tabletojson;
// Fetch a URL and parse all it's tables into JSON, using promisesvar tabletojson = ;var url = '';tabletojson;
// Fetch a table from Wikipedia and combine with json2csv to convert to CSVvar tabletojson = ;var json2csv = ;var url = '';tabletojson;
Improvements, fixes and suggestions for better written modules that other people have created are welcome, as are bug reports against specific tables it is unable to handle.
If there is enough interest and I get some examples that I'll improve the code and actually write some tests.