How to pretty print JSON with React?

To pretty print JSON with React, you can use the JSON.stringify() method and pass JSON object as the first argument, null as the second argument, and the 2 as the third argument. This will return a string representation of the JSON object that is nicely formatted and easy to read.

Here is an example:

import React from 'react';
const json = {
"name": "John Doe",
"age": 32,
"email": "johndoe@example.com"
};
const PrettyJson = () => {
return (
<pre>{JSON.stringify(json, null, 2)}</pre>
);
};

This code will render the JSON object inside a <pre> element, which will preserve the formatting of the stringified JSON. The output will look like this:

{
"name": "John Doe",
"age": 32,
"email": "johndoe@example.com"
}

October 28, 2022
23968