When I require data.json in node Why node doesn't serialise info object in following json structure?
data.json
{
"mailOptions": {
"from": "from me",
"service": "gmail",
"auth": {
"user": "username",
"pass": "password",
"info": {
"name": "myname"
}
}
}
}
The output result is:
> require('./data.json')
{ mailOptions:
{ from: 'from me',
service: 'gmail',
auth: { user: 'username', pass: 'password', info: [Object] } } }
There is an answer here which suggests to use util.inspect function but for some reason it isn't working for me.
So, Two questions:
- I am curious to know the reason behind this
- How I can get the complete object serialised?
Thanks
utilbefore using it?) (Have you set the depth parameter as states here: stackoverflow.com/a/21524533/1525495 ?)data.jsonfile, you actually get an object with all the nested elements. You just have tovar data = require('./data.json');and thenconsole.log(data);and evenconsole.log(data.mailOptions.auth.info);.util.inspect, yeah. Otherwise your question is malformed.