| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 5 |
|
| 6 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 7 |
See the COPYING file for details. |
| 8 |
--> |
| 9 |
<head> |
| 10 |
<title>Demo - goog.format.JsonPrettyPrinter</title> |
| 11 |
<style type="text/css"> |
| 12 |
.goog-jsonprettyprinter-propertyname { |
| 13 |
color: #F00; |
| 14 |
} |
| 15 |
|
| 16 |
.goog-jsonprettyprinter-propertyvalue-string { |
| 17 |
color: #00F; |
| 18 |
} |
| 19 |
|
| 20 |
.goog-jsonprettyprinter-propertyvalue-number { |
| 21 |
color: #0F0; |
| 22 |
} |
| 23 |
|
| 24 |
.goog-jsonprettyprinter-propertyvalue-boolean { |
| 25 |
color: #0F0; |
| 26 |
} |
| 27 |
|
| 28 |
.goog-jsonprettyprinter-propertyvalue-null { |
| 29 |
color: orange; |
| 30 |
} |
| 31 |
</style> |
| 32 |
<script src="../base.js"></script> |
| 33 |
<script> |
| 34 |
goog.require('goog.format.JsonPrettyPrinter'); |
| 35 |
</script> |
| 36 |
<script> |
| 37 |
var obj = { |
| 38 |
'a': null, |
| 39 |
'b': true, |
| 40 |
'c': 1, |
| 41 |
'd': 'd', |
| 42 |
'e': [1, 2, 3], |
| 43 |
'f': { |
| 44 |
'g': 1, |
| 45 |
'h': 'h' |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
function loadCodeTxt() { |
| 51 |
var f = new goog.format.JsonPrettyPrinter(); |
| 52 |
document.getElementById('codeTxt').innerHTML = f.format(obj); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
function loadCodeHtml() { |
| 57 |
var f = new goog.format.JsonPrettyPrinter( |
| 58 |
new goog.format.JsonPrettyPrinter.HtmlDelimiters()); |
| 59 |
document.getElementById('codeHtml').innerHTML = f.format(obj); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
function loader() { |
| 64 |
loadCodeTxt(); |
| 65 |
loadCodeHtml(); |
| 66 |
} |
| 67 |
</script> |
| 68 |
</head> |
| 69 |
<body onload="loader();"> |
| 70 |
|
| 71 |
Pretty-printed JSON. |
| 72 |
<pre id="codeTxt"> |
| 73 |
</pre> |
| 74 |
|
| 75 |
Pretty-printed JSON (Formatted using CSS). |
| 76 |
<pre id="codeHtml"> |
| 77 |
</pre> |
| 78 |
|
| 79 |
</body> |
| 80 |
</html> |