Does jQuery have a JSON/Javascript object to HTML pretty print function similar to PHP\'s var_dump? If yes, what is it?
Although the accepted answer is correct that jQuery does not have a pretty print feature for JSON, that feature is now included in out of the box javascript through JSON.stringify()'s
space argument. To print to HTML, wrapping the output with
will preserve the line spacing for readability purposes.
var obj = {a:1, 'b':'foo', c:[false,'false',null, 'null', {d:{e:1.3e5,f:'1.3e5'}}]};
var str = "" + JSON.stringify(obj, undefined, 4) + "
";
/* Returns
{
"a": 1,
"b": "foo",
"c": [
false,
"false",
null,
"null",
{
"d": {
"e": 130000,
"f": "1.3e5"
}
}
]
}
*/