Reputation: 47
I'm trying to access a JSON object but I'm getting errors while accessing the object id. Could you please go through the code and let me know the mistake I'm making.
When I try to console.log(obj.id);
it says undefined
Here is the code:
var orderidfirstuser = fs.readFileSync(`orderids/${orderid}.json`,'utf-8');
var obj = JSON.parse(orderidfirstuser);
obj.id = (obj.id);
console.log(obj.id);
obj.delivered = (obj.delivered);
obj.title = (obj.title);
obj.is_replacement = (obj.is_replacement);
obj.paid_at = (obj.paid_at);
Upvotes: 1
Views: 244
Reputation: 47
It turns out that I was saving the unparsed object. That's why when I tried to read it caused this issue.
Upvotes: 1