function stringify(obj, whitespace, isChild) { if (!obj) { return 'null'; } var output = (obj instanceof Array ? '[' : '{') + '\n'; for (var i = 0, keyList = Object.keys(obj), l = keyList.length; i < l; i++ ) { var key = keyList[i]; var prop = obj[key]; var stringifyValue = 'null'; if (prop != null) { switch (typeof prop) { case "boolean": case "number": stringifyValue = prop; break; case "string": stringifyValue = '"'+ prop +'"'; break; default: if (prop instanceof RegExp || prop instanceof Number || prop instanceof Boolean ) { stringifyValue = prop.toString(); } else if (prop instanceof String) {; stringifyValue = '"' + prop.toString() + '"'; } else if (prop instanceof Function) { stringifyValue = prop.toString().replace(/\r?\n/g, '\n' + whitespace); } else { stringifyValue = stringify(prop, whitespace + whitespace, true); } break; } } output += whitespace + key + ' = ' + stringifyValue + ';\n'; } output += (isChild ? whitespace.slice(0, whitespace.length / 2) : '') + (obj instanceof Array ? ']' : '}'); return output; }