Monday 24 February 2020

JSON Parse with Underscores

Hi,Just starting to use node.js and trying to get the value of liquidity_score from the json below.https://api.coingecko.com/api/v3/coins/bitcoin.jsonIf I try to get any value from a object with a underscore in it doesn't work. I've tried searching the web but is there something really simple I am missing?const https = require('https'); const httpGet = () => { return new Promise(((resolve, reject) => { var options = { host: 'api.coingecko.com', port: 443, path: '/api/v3/coins/bitcoin', method: 'GET', }; const request = https.request(options, (response) => { response.setEncoding('utf8'); let returnData = ''; response.on('data', (chunk) => { returnData += chunk; }); response.on('end', () => { resolve(JSON.parse(returnData)); }); response.on('error', (error) => { reject(error); }); }); request.end(); })); } async handle(handlerInput) { //const speakOutput = 'The Bitcoin price today is'; const response = await httpGet(); const speakOutput = response.liquidity_score; return handlerInput.responseBuilder .speak(speakOutput) //.reprompt('add a reprompt if you want to keep the session open for the user to respond') .getResponse(); } };

Submitted February 24, 2020 at 04:40PM by spenana

No comments:

Post a Comment