Home

Display javascript object in JSON format in the UI

While debugging your javascript code, you may have used console.log.

But if you want to display the object in the UI, you need to convert it to a string. Using JSON.stringify in this case will be very helpful.

This is the snippet that I use to display javascript object directly in UI.

The following code uses jsx which I use in React.

<pre>{JSON.stringify(obj, null, 2)}</pre>


Last Updated on

Next Post: Rules vs Guidelines →

Comments