Skip to content

Commit d7f31bb

Browse files
author
Emmanouil Konstantinidis
committed
Simpler JSON pretty print
1 parent 96b8d4a commit d7f31bb

File tree

6 files changed

+31
-364
lines changed

6 files changed

+31
-364
lines changed

rest_framework_docs/static/rest_framework_docs/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
var jsonPP = {
2+
// Thanks to http://jsfiddle.net/unlsj/
3+
replacer: function (match, pIndent, pKey, pVal, pEnd) {
4+
var key = '<span class=json-key>';
5+
var val = '<span class=json-value>';
6+
var str = '<span class=json-string>';
7+
var r = pIndent || '';
8+
if (pKey)
9+
r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
10+
if (pVal)
11+
r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
12+
return r + (pEnd || '');
13+
},
14+
prettyPrint: function (obj) {
15+
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
16+
return JSON.stringify(obj, null, 3)
17+
.replace(/&/g, '&amp;').replace(/\\"/g, '&quot;')
18+
.replace(/</g, '&lt;').replace(/>/g, '&gt;')
19+
.replace(jsonLine, this.replacer);
20+
}
21+
};
22+
123
$( document ).ready(function() {
224

325
var setResponse = function (response) {
@@ -28,7 +50,7 @@ $( document ).ready(function() {
2850
$('#responseStatusCode').addClass(statusCodeClass);
2951

3052
$('#responseStatusText').text(response.statusText.toLowerCase());
31-
$('#responseData').JSONView(response.responseJSON);
53+
$('#responseData').html(jsonPP.prettyPrint(response.responseJSON));
3254

3355
// console.log(response);
3456
// console.log(response.responseJSON);

rest_framework_docs/static/rest_framework_docs/js/jsonview.js

Lines changed: 0 additions & 284 deletions
This file was deleted.

0 commit comments

Comments
 (0)