How do you log content of a JSON object in Node.js?


Is it possible to print an objects contents e.g. methods and attributes in Node.js?

At the moment I’m trying to print the session object and get the following:

console.log("Session:" + session);
> Session:[object Object]

Maybe in a similar way to print_r(array) in PHP, or using .toString in Java.


Try this one:

console.log("Session: %j", session);

If the object could be converted into JSON, that will work.

Answered By – Alexander Sulfrian

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.