When I use JSON.parse and log out some fetched data with the require
module, nested objects are logged [Object]
. Here is an example (currently using Node version 10.15):
const request = require("request");
const url = "https://www.reddit.com/r/javascript.json";
request(url, (error, response) => {
const data = JSON.parse(response.body);
console.log(data)
});
{ kind: 'Listing',
data:
{ modhash: '',
dist: 26,
children:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ],
after: 't3_bf4cl6',
before: null } }
I was looking at this question: JSON.parse returns [object] from JSON
The person asking is curious why after JSON.parse, objects get logged as [Object]
. The top answer states that the reason JSON.parse hides the data is for readability. But the answer doesn't explain a way to override the default behavior.
How do I get JSON.parse to log the full data? Is there a way to override the default behavior?