Skip to content

Commit b9d2e31

Browse files
Show JSON information inside pre blocks with pretty format (#246)
* Add pre block to information cells that contain json object strings
1 parent b908249 commit b9d2e31

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/main/resources/static/js/common.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ function isStringDefined(value) {
104104
return isDefined;
105105
}
106106

107+
function parseJsonObject(value) {
108+
try {
109+
var json = JSON.parse(value);
110+
if (json !== null && typeof json === "object") {
111+
return json;
112+
} else {
113+
return undefined;
114+
}
115+
} catch (e) {
116+
return undefined;
117+
}
118+
}
119+
107120
// /Stop ## Common functions ##################################
108121

109122
// Start ## Routing ##

src/main/resources/static/js/information.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,17 @@ jQuery(document).ready(function () {
109109
tdKey.setAttribute('class', 'left-table-pane');
110110
tdKey.appendChild(document.createTextNode(key));
111111
tr.appendChild(tdKey);
112-
var tdValue = document.createElement('td');
113-
tdValue.appendChild(document.createTextNode(value));
114-
tr.appendChild(tdValue);
112+
var element = document.createElement('td');
113+
var json = parseJsonObject(value);
114+
if (json != undefined) {
115+
value = JSON.stringify(json, undefined, 2);
116+
pre = document.createElement('pre');
117+
pre.appendChild(document.createTextNode(value));
118+
element.appendChild(pre);
119+
} else {
120+
element.appendChild(document.createTextNode(value));
121+
}
122+
tr.appendChild(element);
115123
return tr;
116124
}
117125

0 commit comments

Comments
 (0)