kshitiz
kshitiz

Reputation: 65

I Have been trying to access data in json file using node js but getting the output as undefined

var fs =require('fs');

var contents=fs.readFileSync('./emailsender.json');

var jsoncontent=JSON.parse(contents);

console.log(jsoncontent["to"]);

emailsender.json

[{"to":"[email protected]","from":"[email protected]"},{"to":"[email protected]","from":"[email protected]"}]

Upvotes: 0

Views: 32

Answers (1)

squgeim
squgeim

Reputation: 2351

console.log(jsoncontent[0].to)

jsoncontent is an array of objects.

Upvotes: 1

Related Questions