| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 | <title>Test JSON.minify()</title> |
| 6 | |
| 7 | <script type="text/javascript" src="json2.js"></script> |
| 8 | <script type="text/javascript" src="minify.json.js"></script> |
| 9 | |
| 10 | </head> |
| 11 | |
| 12 | <body> |
| 13 | <h1>Test JSON.minify()</h1> |
| 14 | |
| 15 | <p>test #1</p> |
| 16 | <textarea id="orig_json1" cols="50" rows="12"> |
| 17 | // this is a JSON file with comments |
| 18 | { |
| 19 | "foo": "bar", // this is cool |
| 20 | "bar": [ |
| 21 | "baz", "bum", "zam" |
| 22 | ], |
| 23 | /* the rest of this document is just fluff |
| 24 | in case you are interested. */ |
| 25 | "something": 10, |
| 26 | "else": 20 |
| 27 | } |
| 28 | |
| 29 | /* NOTE: You can easily strip the whitespace and comments |
| 30 | from such a file with the JSON.minify() project hosted |
| 31 | here on github at http://github.com/getify/JSON.minify |
| 32 | */ |
| 33 | </textarea> |
| 34 | <p>result #1</p> |
| 35 | <textarea id="new_json1" cols="50" rows="12"></textarea> |
| 36 | |
| 37 | |
| 38 | <p>test #2</p> |
| 39 | <textarea id="orig_json2" cols="50" rows="12"> |
| 40 | |
| 41 | {"/*":"*/","//":"",/*"//"*/"/*/":// |
| 42 | "//"} |
| 43 | |
| 44 | </textarea> |
| 45 | <p>result #2</p> |
| 46 | <textarea id="new_json2" cols="50" rows="12"></textarea> |
| 47 | |
| 48 | |
| 49 | <p>test #3</p> |
| 50 | <textarea id="orig_json3" cols="50" rows="12"> |
| 51 | /* |
| 52 | this is a |
| 53 | multi line comment */{ |
| 54 | |
| 55 | "foo" |
| 56 | : |
| 57 | "bar/*"// something |
| 58 | , "b\"az":/* |
| 59 | something else */"blah" |
| 60 | |
| 61 | } |
| 62 | </textarea> |
| 63 | <p>result #3</p> |
| 64 | <textarea id="new_json3" cols="50" rows="12"></textarea> |
| 65 | |
| 66 | |
| 67 | <p>test #4</p> |
| 68 | <textarea id="orig_json4" cols="50" rows="12"> |
| 69 | {"foo": "ba\"r//", "bar\\": "b\\\"a/*z", |
| 70 | "baz\\\\": /* yay */ "fo\\\\\"*/o" |
| 71 | } |
| 72 | </textarea> |
| 73 | <p>result #4</p> |
| 74 | <textarea id="new_json4" cols="50" rows="12"></textarea> |
| 75 | |
| 76 | |
| 77 | |
| 78 | <script type="text/javascript"> |
| 79 | |
| 80 | var old; |
| 81 | for (var i=1; i<=4; i++) { |
| 82 | old = document.getElementById("orig_json"+i).value; |
| 83 | document.getElementById("new_json"+i).value = JSON.minify(old); |
| 84 | } |
| 85 | |
| 86 | </script> |
| 87 | |
| 88 | </body> |
| 89 | </html> |