Format JSON for inspecting objects

This patch enables formatting for inspecting JSON objects. Example:

p({foo: "bar", deep: {foo: "bar"}})

becomes:

{
 "foo": "bar",
 "deep": {
  "foo": "bar"
 }
}
This commit is contained in:
Felix Geisendörfer 2009-11-16 11:21:23 +01:00 committed by Ryan Dahl
parent ca2c7d1745
commit 6e9e61b9df

View File

@ -28,7 +28,7 @@ exports.inspect = function (value) {
if (value === undefined) return;
try {
return JSON.stringify(value);
return JSON.stringify(value, undefined, 1);
} catch (e) {
// TODO make this recusrive and do a partial JSON output of object.
if (e.message.search("circular")) {