jsonprettyprinter.html 1.4 KB

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