Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (27 sloc) 823 Bytes
layout title date excerpt categories
post
How to prettify a JavaScript object
2017-03-20 04:03:00 -4000
How to prettify a POJO (Plain Old JavaScript Object).
javascript pojo json prettify

Assuming you have a POJO (Plain Old JavaScript Object):

var object = {
    key: 'value'
    // properties...
};

JSON.stringify can be used to prettify the output:

console.log(
    JSON.stringify(object, null, 4);
);

If you're using Node.js and your object has circular references, you'll want to use something like util.inspect:

var util = require('util');
console.log(
    util.inspect(object, { depth: null });
);