I\'m using ReactJS and part of my app requires pretty printed JSON.
I get some JSON like: { \"foo\": 1, \"bar\": 2 }, and if I run that through
{ \"foo\": 1, \"bar\": 2 }
const getJsonIndented = (obj) => JSON.stringify(newObj, null, 4).replace(/["{[,\}\]]/g, "") const JSONDisplayer = ({children}) => ( {getJsonIndented(children)} )
{getJsonIndented(children)}
Then you can easily use it:
const Demo = (props) => { .... return {someObj} }