To quickly debug something, or temporarily show the data object during development, just to know what you’re working with, it comes in handy to print the full JSON object. Not as a string that’s almost impossible to read, but as a well formatted array.
We’ve got a neat little one-liner for that, which I’ll share below
<pre>{JSON.stringify(data, null, 2)}</pre>
The JSON.stringify commands accepts 3 parameters: the value, the replacer, and the amount of spaces.
That means that you can also print the array with some more spacing, with the code below:
<pre>{JSON.stringify(document, null, 4)}</pre>
Leave a Reply