Created
August 25, 2010 15:46
-
-
Save jimfleming/549747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json_escape = function(value) { | |
if (value.replace) | |
return value.replace(/\//g, '\\/') | |
else | |
return value | |
} | |
var json_to_html = function(json, level) { | |
level = level || 0 | |
if (!level) { | |
$('body > pre').append('{\n') | |
json_to_html(json, 1) | |
$('body > pre').append('}\n') | |
} else { | |
var j = 0; | |
for (var i in json) { | |
var is_object = typeof json[i] == 'object' | |
$('body > pre').append('\t'.repeat(level) + '<strong>"' + i + '"</strong>:' + (!is_object ? '"<span class="no-whitespace">' + json_escape(json[i]) + '</span>"' + (j != json.length - 1 ? ',' : '') : '{') + '\n') | |
if (is_object) | |
json_to_html(json[i], level + 1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment