pretty-print JSON using JavaScript

Pretty-printing is implemented natively in JSON.stringify(). The third argument enables pretty printing and sets the spacing to use: If you need syntax highlighting, you might use some regex magic like so: See in action here: jsfiddle Or a full snippet provided below: Show code snippet