Converts html tables to JSON and JS objects
Install via npm
npm install jsonfromtable
const jsonfromtable = require('jsonfromtable')
jsonfromtable(options, headers).then((data) => {
console.log(data)
})
jsonfromtable
function takes two arguments options
and headers
and returns promise.
Check this example in codesandbox.
If you want the output from a url then you need to pass url
option. The url should be of a webpage which has a table.
options = {
url: 'https://www.example.com',
}
If you want the output from a html then you need to pass html
option. The html should contain table
tag.
options = {
html: '<table>....</table>',
}
If you want the json output then you can pass format
option.
options = {
url: 'https://www.example.com',
format: 'json', // default => jsobject
}
If the page has more than one table, then you can pass id of the table as selector
.
options = {
url: 'https://www.example.com',
selector: '#table_example', // default => table
}
The first row from table is taken a key. You can also pass your own headers
options = {
url: 'https://www.example.com',
selector: '#table_example', // default => table
headers: ['header1', 'header2', 'header3'],
}
MIT