2

I am trying to convert a table to JSON, to search for data easily, the URL is: http://www.tppcrpg.net/rarity.html

I found this package: https://www.npmjs.com/package/tabletojson

I tried to use it like:

'use strict';

const tabletojson = require('tabletojson');

        tabletojson.convertUrl(
            'http://www.tppcrpg.net/rarity.html',
            { useFirstRowForHeadings: true },
            function(tablesAsJson) {
                console.log(tablesAsJson[1]);
            }
        );

However it returns undefined in the console, are there any alternative options or am I using the package wrong?

6
  • Do you want to convert this remote url? Commented Sep 16, 2018 at 6:56
  • Yes I want to get the data in JSON because I wouldn't know how to get data from a row in table format Commented Sep 16, 2018 at 7:01
  • is the tppcrg url is yours? Commented Sep 16, 2018 at 7:04
  • No it is not mine Commented Sep 16, 2018 at 7:06
  • Ok you are unable to access there data of third party api, but you want that data, so you are trying this am i correct? Commented Sep 16, 2018 at 7:06

1 Answer 1

1

Hey you are actually getting data, change the console.log

Your output have total one array only but you are putting tablesAsJson[1] in console, but array index starts with [0].

'use strict';

    const tabletojson = require('tabletojson');
    tabletojson.convertUrl(
        'http://www.tppcrpg.net/rarity.html',
        function(tablesAsJson) {
            console.log(tablesAsJson[0]);
        }
    );

For better looking code:

const url = 'http://www.tppcrpg.net/rarity.html';
tabletojson.convertUrl(url)
  .then((data) => {
    console.log(data[0]);
  })
  .catch((err) => { 
     console.log('err', err);
   }); // to catch error
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.