Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function prettify() {
- function output(inp) {
- document.body.appendChild(document.createElement('pre')).innerHTML = inp;
- }
- function syntaxHighlight(json) {
- json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
- return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
- var cls = 'number';
- if (/^"/.test(match)) {
- if (/:$/.test(match)) {
- cls = 'key';
- } else {
- cls = 'string';
- }
- } else if (/true|false/.test(match)) {
- cls = 'boolean';
- } else if (/null/.test(match)) {
- cls = 'null';
- }
- return '<span class="' + cls + '">' + match + '</span>';
- });
- }
- var tag = document.createElement("style");
- tag.type = "text/css";
- document.getElementsByTagName("head")[0].appendChild(tag);
- tag[(typeof document.body.style.WebkitAppearance == "string") ? "innerText" : "innerHTML"] = "pre{outline:#ccc solid 1px;padding:5px;margin:5px}.string{color:green}.number{color:#ff8c00}.boolean{color:#00f}.null{color:#ff00ff}.key{color:red;}"
- // output(syntaxHighlight(JSON.parse(document.body.innerText.replace("'", "\""))));
- $.get(window.location.href).done(function(data) {
- output(syntaxHighlight(JSON.stringify(data, null, 2)));
- });
- }
Add Comment
Please, Sign In to add comment