How to parse JSON in node js? How to parse JSON in node js? json json

How to parse JSON in node js?


When you call msf.getData(league, season, feed, format, and any other applicable params for the feed) with format 'json'. It return a json object. As a result your data will be a json object.

msf.authenticate("username", "password");var data = msf.getData('nba', '2016-2017-regular', 'cumulative_player_stats', 'json', {player: 'nick-young'});console.log(data["cumulativeplayerstats"]["playerstatsentry"][0]["stats"]["PtsPerGame"]["#text"]);

Read json file content using fs.readFile

Sync

const fs = require('fs');const json = JSON.parse(fs.readFileSync('results/cumulative_player_stats-nba-2016-2017-regular.json', 'utf8'));

Async

const fs = require('fs');fs.readFile('results/cumulative_player_stats-nba-2016-2017-regular.json', 'utf8', (err, data) => {  if (err) throw err;  const json = JSON.parse(data);  console.log(json["cumulativeplayerstats"]["playerstatsentry"][0]["stats"]["PtsPerGame"]["#text"]);});