Using Node.JS,read a JSON object?
https://www.npmjs.com/package/jsonfile
// Read Asynchrously
// D:\NodeJs>node readAsync.js
// Define JSON File
var fs = require("fs");
console.log("***STARTING***\n");
//Get content from file
//ES 5
var contents = fs.readFile('dummy.json', 'utf8', function (err, data) {
if (err) throw err;
console.log("data =" + data);
});
//ES 6
/*var contents = fs.readFile('dummy.json', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});*/
// Define to JSON type
var jsonContent = JSON.parse(contents);
// Get Value from JSON
console.log("User Name:", jsonContent.username);
console.log("Email:", jsonContent.email);
console.log("Password:", jsonContent.password);
console.log("\n***EXIT***");
{
"username": "xyz",
"password": "xyz@123",
"email": "[email protected]",
"uid": 1100
}
???
https://github.com/jprichardson/node-jsonfile