Coder Social home page Coder Social logo

sonroyaalmerol / html-table-to-json Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brandon93s/html-table-to-json

0.0 0.0 0.0 417 KB

Generate JSON representations of HTML tables

Home Page: https://www.npmjs.com/package/html-table-to-json

License: MIT License

JavaScript 100.00%

html-table-to-json's Introduction

html-table-to-json Build Status

Extracts tables from a provided html snippet and converts them to JSON objects

Install

$ npm install html-table-to-json

Usage

const HtmlTableToJson = require('html-table-to-json');

const jsonTables = HtmlTableToJson.parse(`
        <table>
            <tr>
                <th>Animal</th>
                <th>Color</th>
                <th>Name</th>
            </tr>
            <tr>
                <td>Unicorn</td>
                <td>Pink</td>
                <td>Billy</td>
            </tr>
            <tr>
                <td>Walrus</td>
                <td>Orange</td>
                <td>Sue</td>
            </tr>
        </table>
    `);

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:

// 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

html-table-to-json's People

Contributors

brandon93s avatar normanperrin avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.