When I call JSON.stringify() on a complex object in JavaScript, it produces a string with lots of escape sequences (\\\", \\\\\", etc.).
How can I make it create a h
I would use JSON.stringify(),
The
JSON.stringify()
method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.
with four spaces and an appropriate display environment with
....
The result is good, readable, and copyable for other use.
var object = { name: 'void', type1: "O'\"This", type2: 'O\'That', a: [1, 2, 3] };
document.write('' + JSON.stringify(object, 0, 4) + '
');