AngularJS log JSON AngularJS log JSON angularjs angularjs

AngularJS log JSON


You can stringify it before printing.

console.log("User = " + JSON.stringify(data));


You can also use angular.toJson() if you don't want to add a new dependency:

$log.debug(angular.toJson(data, true));

Reference


Depending on your browser, the log function can take multiple parameters. Chrome, for instance, supports this:

console.log("User = ", data);

When you do this, data shows up in an object browser which you can show/collapse the hierarchy. It is extremely useful. Since I develop in Chrome, I vastly prefer this method (over JSON.stringify) because it is less typing and the debugging experience is better.

If you are stuck debugging in a browser that doesn't support this syntax, then JSON.stringify is probably your best bet.