JSON.stringify with pretty print

Posted on 12/1/2015 @ 5:31 PM in #Vanilla .NET by | Feedback | 2106 views

If you want to get a string representation of a JavaScript object, you can do JSON.stringify.
But sometimes we save this object to a file, so humans can read it.
In those scenarios, it’s nice to be able to insert some whitespace/indentation so the damn thing is readable and editable by humans.

Just substitute, JSON.stringify(object) with JSON.stringify(object, null, 2);

And you have pretty print!

Sound off but keep it civil:

Older comments..