| 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="minify.json.js"></script> |
| 8 |
|
| 9 |
</head> |
| 10 |
|
| 11 |
<body onload="check()"> |
| 12 |
<h1>Test JSON.minify()</h1> |
| 13 |
|
| 14 |
<pre>console.log views.</pre> |
| 15 |
|
| 16 |
<p>test #1</p> |
| 17 |
<textarea id="orig_json1" cols="50" rows="12"> |
| 18 |
// this is a JSON file with comments |
| 19 |
{ |
| 20 |
"foo": "bar", // this is cool |
| 21 |
"bar": [ |
| 22 |
"baz", "bum", "zam" |
| 23 |
], |
| 24 |
/* the rest of this document is just fluff |
| 25 |
in case you are interested. */ |
| 26 |
"something": 10, |
| 27 |
"else": 20 |
| 28 |
} |
| 29 |
|
| 30 |
/* NOTE: You can easily strip the whitespace and comments |
| 31 |
from such a file with the JSON.minify() project hosted |
| 32 |
here on github at http://github.com/getify/JSON.minify |
| 33 |
*/ |
| 34 |
</textarea> |
| 35 |
<p>result #1</p> |
| 36 |
<textarea id="new_json1" cols="50" rows="12"></textarea> |
| 37 |
|
| 38 |
|
| 39 |
<p>test #2</p> |
| 40 |
<textarea id="orig_json2" cols="50" rows="12"> |
| 41 |
|
| 42 |
{"/*":"*/","//":"",/*"//"*/"/*/":// |
| 43 |
"//"} |
| 44 |
|
| 45 |
</textarea> |
| 46 |
<p>result #2</p> |
| 47 |
<textarea id="new_json2" cols="50" rows="12"></textarea> |
| 48 |
|
| 49 |
|
| 50 |
<p>test #3</p> |
| 51 |
<textarea id="orig_json3" cols="50" rows="12"> |
| 52 |
/* |
| 53 |
this is a |
| 54 |
multi line comment */{ |
| 55 |
|
| 56 |
"foo" |
| 57 |
: |
| 58 |
"bar/*"// something |
| 59 |
, "b\"az":/* |
| 60 |
something else */"blah" |
| 61 |
|
| 62 |
} |
| 63 |
</textarea> |
| 64 |
<p>result #3</p> |
| 65 |
<textarea id="new_json3" cols="50" rows="12"></textarea> |
| 66 |
|
| 67 |
|
| 68 |
<p>test #4</p> |
| 69 |
<textarea id="orig_json4" cols="50" rows="12"> |
| 70 |
{"foo": "ba\"r//", "bar\\": "b\\\"a/*z", |
| 71 |
"baz\\\\": /* yay */ "fo\\\\\"*/o" |
| 72 |
} |
| 73 |
</textarea> |
| 74 |
<p>result #4</p> |
| 75 |
<textarea id="new_json4" cols="50" rows="12"></textarea> |
| 76 |
|
| 77 |
|
| 78 |
<p>test #5</p> |
| 79 |
<textarea id="orig_json5" cols="50" rows="12"> |
| 80 |
/** a */[{"foo": "ba\"r//", "bar\\": "b\\\"a/*z", |
| 81 |
"baz\\\\": /* yay */ "fo\\\\\"*/o", |
| 82 |
"spa\\\\m": /* aja*/ [ { "a": [1,2,3,4]}, {"b": 2}] |
| 83 |
} /** aa */] //aaaa\n//aaaa |
| 84 |
</textarea> |
| 85 |
<p>result #5</p> |
| 86 |
<textarea id="new_json5" cols="50" rows="12"></textarea> |
| 87 |
|
| 88 |
|
| 89 |
<button name="check" onclick="check()">check!!</button> |
| 90 |
|
| 91 |
<script type="text/javascript"> |
| 92 |
|
| 93 |
function check() { |
| 94 |
var old; |
| 95 |
for (var i = 1; i <= 5; i++) { |
| 96 |
old = document.getElementById("orig_json" + i).value; |
| 97 |
var minify = JSON.minify(old); |
| 98 |
try { |
| 99 |
console.log("index:", i); |
| 100 |
console.log(JSON.parse(minify)); |
| 101 |
} catch(e) { |
| 102 |
console.error(e); |
| 103 |
} |
| 104 |
document.getElementById("new_json" + i).value = minify; |
| 105 |
} |
| 106 |
} |
| 107 |
</script> |
| 108 |
|
| 109 |
</body> |
| 110 |
</html> |