forked from abodelot/jquery.json-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
104 lines (99 loc) · 2.74 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!doctype HTML>
<html>
<head>
<title>jQuery json-viewer</title>
<meta charset="utf-8" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="json-viewer/jquery.json-viewer.js"></script>
<link href="json-viewer/jquery.json-viewer.css" type="text/css" rel="stylesheet">
<style type="text/css">
body {
margin: 0 100px;
font-family: sans-serif;
}
p.options label {
margin-right: 10px;
}
p.options input[type=checkbox] {
vertical-align: middle;
}
textarea#json-input {
width: 100%;
height: 200px;
}
pre#json-renderer {
border: 1px solid #aaa;
}
</style>
<script>
$(function() {
function renderJson() {
try {
var input = eval('(' + $('#json-input').val() + ')');
}
catch (error) {
return alert("Cannot eval JSON: " + error);
}
var options = {
collapsed: $('#collapsed').is(':checked'),
rootCollapsable: $('#root-collapsable').is(':checked'),
withQuotes: $('#with-quotes').is(':checked'),
withLinks: $('#with-links').is(':checked')
};
$('#json-renderer').jsonViewer(input, options);
}
// Generate on click
$('#btn-json-viewer').click(renderJson);
// Generate on option change
$('p.options input[type=checkbox]').click(renderJson);
// Display JSON sample on page load
renderJson();
});
</script>
</head>
<body>
<h1><a href="https://github.com/abodelot/jquery.json-viewer">jQuery json-viewer</a></h1>
<textarea id="json-input" autocomplete="off">
{
"id": 1001,
"type": "donut",
"name": "Cake",
"description": "https://en.wikipedia.org/wiki/Doughnut",
"price": 2.55,
"available": {
store: 42,
warehouse: 600
},
"toppings": [
{ "id": 5001, "type": "None" },
{ "id": 5002, "type": "Glazed" },
{ "id": 5005, "type": "Sugar" },
{ "id": 5003, "type": "Chocolate" },
{ "id": 5004, "type": "Maple" }
],
"uuids": [
"826b23ce-2669-4122-981f-3e2e4429159d",
"e32111a0-6a87-49ab-b58f-a01bf8d28ba0",
"c055a894-698e-41c0-b85f-7510a7351d9d",
],
}</textarea>
<p class="options">
Options:
<label title="Generate node as collapsed">
<input type="checkbox" id="collapsed">Collapse nodes
</label>
<label title="Allow root element to be collasped">
<input type="checkbox" id="root-collapsable" checked>Root collapsable
</label>
<label title="Surround keys with quotes">
<input type="checkbox" id="with-quotes">Keys with quotes
</label>
<label title="Generate anchor tags for URL values">
<input type="checkbox" id="with-links" checked>
With Links
</label>
</p>
<button id="btn-json-viewer" title="run jsonViewer()">Transform to HTML</button>
<pre id="json-renderer"></pre>
</body>
</html>