Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandon93s/html-table-to-json
Generate JSON representations of HTML tables
https://github.com/brandon93s/html-table-to-json
html-table json scraping
Last synced: about 2 months ago
JSON representation
Generate JSON representations of HTML tables
- Host: GitHub
- URL: https://github.com/brandon93s/html-table-to-json
- Owner: brandon93s
- License: mit
- Created: 2016-07-23T02:38:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-30T16:05:50.000Z (over 4 years ago)
- Last Synced: 2024-10-28T17:38:55.712Z (3 months ago)
- Topics: html-table, json, scraping
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/html-table-to-json
- Size: 359 KB
- Stars: 41
- Watchers: 4
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# html-table-to-json [![Build Status](https://travis-ci.org/brandon93s/html-table-to-json.svg?branch=master)](https://travis-ci.org/brandon93s/html-table-to-json)
> Extracts tables from a provided html snippet and converts them to JSON objects
## Install
```
$ npm install html-table-to-json
```## Usage
```js
const HtmlTableToJson = require('html-table-to-json');const jsonTables = HtmlTableToJson.parse(`
Animal
Color
Name
Unicorn
Pink
Billy
Walrus
Orange
Sue
`);console.log(jsonTables.results);
/* => [[
* {Animal: 'Unicorn', Color: 'Pink', Name: 'Billy'},
* {Animal: 'Walrus', Color: 'Orange', Name: 'Sue'}
* ]]
*/console.log(jsonTables.count);
// => 1```
## API
### HtmlTableToJson.parse(input [,options])
#### input
Type: `string`
Any html snippet.
#### options
Type: `object`
##### values
Type: `bool`
Return table rows as value arrays:
```js
// HtmlTableToJson.parse(html, { values: true })
/* => [[
* ['Unicorn', 'Pink', 'Billy'],
* ['Walrus', 'Orange', 'Sue']
* ]]
*/
```## Headers
HtmlTableToJson extracts table headers ( `th` ) to be used as JSON object keys. The first row is used when no `th` elements are present.
## License
MIT © [Brandon Smith](https://github.com/brandon93s)