function pretifyJson(json) {
if (typeof json !== 'string') {
json = JSON.stringify(json, undefined, 4);
}
let jsonStr = json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
function (match) {
let cls = "<span>";
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = "<span class='key'>";
} else {
cls = "<span class='string'>";
}
} else if (/true|false/.test(match)) {
cls = "<span class='boolean'>";
} else if (/null/.test(match)) {
cls = "<span class='null'>";
}
return cls + match + "</span>";
}
);
let line = '<br/> ';
jsonStr = jsonStr.replaceAll('</span>,', '</span>,' + line)
.replaceAll('{<span', '{' + line + '<span')
.replaceAll('</span>}', '</span>' + line + '}')
jsonStr = jsonStr.split('</span>,').join('</span>,' + line)
.split('{<span').join('{' + line + '<span')
.split('</span>}').join('</span>' + line + '}');
return jsonStr;
}
#data_info{
width: 100%;
font-size: 16px;
white-space: pre-wrap;
word-wrap: break-word;
border:0px;
}
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }