const JsonText = ({ object }) => {
const json = JSON.stringify(object);
let brace = 0;
const formattedJson = json.replace(
/({|}[,]*|[^{}:]+:[^{}:,]*[,{]*)/g,
(m, p1) => {
const returnFunction = () =>
`<div style="text-indent: ${brace * 20}px;">${p1}</div>`;
let returnString = 0;
if (p1.lastIndexOf("{") === p1.length - 1) {
returnString = returnFunction();
brace += 1;
} else if (p1.indexOf("}") === 0) {
brace -= 1;
returnString = returnFunction();
} else {
returnString = returnFunction();
}
return returnString;
}
);
return (
<pre> {formattedJson} </pre>
)
}