-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
77 lines (70 loc) · 2.29 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>format-to-json</title>
<style>
h2 {
text-align: center;
margin: 5px 0;
}
h4 {
font-weight: 400;
text-align: center;
margin: 5px 0 10px;
}
div.status {
text-align: center;
}
div.content {
display: flex;
justify-content: center;
}
label {
line-height: 25px;
}
textarea {
margin: 5px 10px 10px 0;
}
</style>
<script src="./fmt2json.js"></script>
<!-- <script src="https://unpkg.com/format-to-json@3.0.3/fmt2json.min.js"></script> -->
</head>
<body>
<h2>format-to-json (v3.0.3)</h2>
<h4>Format a string to a json like template.</h4>
<div class="status">
<textarea id="status" name="result" id="" cols="84" rows="8" disabled></textarea>
</div>
<div class="content">
<div>
<label for="source">Format Source</label>
<button onclick="formatToJson()">Format</button><br>
<textarea id="source" name="source" id="" cols="40" rows="30"></textarea><br>
</div>
<div>
<label for="result">Format Result:</label><br>
<textarea id="result" name="result" id="" cols="40" rows="30"></textarea>
</div>
</div>
<script>
const status = document.querySelector('#status');
const source = document.querySelector('#source');
const result = document.querySelector('#result');
source.value = '{"zjson":"ZJSON","description":"Online json formatter","version":"v4.1.8","updateTime":"2018-11-23","url":"http://zjson.net","project":"http://github.com/CN-Tower/zjson","language":["中文(简体)","English"],"keywords":["zjson","json formatter"],"content":{"array":["element 001","element 002"],"boolean":true,"null":null,"number":123,"string":"Hello World","object":{"property":"value","key":"val"}}}';
function formatToJson() {
const fmtInfo = fmt2json(source.value, { withDetails: true });
console.log(fmtInfo);
result.value = fmtInfo.result;
delete fmtInfo.result
let fmtStatus = '';
for (const key in fmtInfo) {
fmtStatus += `${key}: ${fmtInfo[key] || '--'};\n`
}
status.value = fmtStatus;
}
formatToJson()
</script>
</body>
</html>