Browsers have built-in pretty printing for JSON

This pretty-prints a JSON object, with two spaces of indentation:

JSON.stringify(object, null, 2)
Henning Koch