Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested objects in response not logging to console

My server gets a response from another server with a document from a mongodb database with a body similar to

{
    messageDetails: {
        body: "hello"
    },
    customerDetails: {
        cstmrFirstName: 'Random',
        cstmrLastName: 'Name',
    },
}

But the response with the body is being logged to the console as:

{
  messageDetails: [Object],
  customerDetails: [Object],
}

How can I log the full object to the console with each object's properties?

like image 410
darkshadowtrail Avatar asked Dec 11 '25 21:12

darkshadowtrail


2 Answers

You can use console.dir. To print with unlimited depth, use {depth: null} option:

console.dir(body, {depth: null});
like image 129
Alexandr Belan Avatar answered Dec 13 '25 10:12

Alexandr Belan


Try console.log(JSON.stringify(body))
Checkout MDN doc JSON.stringify() for more details

like image 30
elainemakyl Avatar answered Dec 13 '25 11:12

elainemakyl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!