-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (55 loc) · 1.48 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JSON Validator</title>
<script type="module">
const input = document.getElementById("file-input");
const message = document.getElementById("message");
input.addEventListener("change", async (e) => {
const file = e.target.files[0];
const text = await file.text();
try {
JSON.parse(text);
message.innerHTML = `<div>Valid <code>JSON</code> ✅<div/>`;
} catch (e) {
message.innerHTML = `<div>Invalid <code>JSON</code> ❌ at ${
e.message.split(" at ")[1]
}<div/>`;
}
});
</script>
<style>
.container {
padding-top: 10px;
max-width: 500px;
margin: auto;
display: flex;
flex-direction: column;
}
h1 {
font-size: 30px;
}
code {
border-radius: 3px;
background-color: gainsboro;
padding: 4px;
font-size: 0.9em;
}
#message {
padding-top: 20px;
font-size: 20px;
font-weight: 500;
}
</style>
</head>
<body>
<div class="container">
<h1><code>JSON</code> validator</h1>
<input name="file" accept=".json" type="file" id="file-input" />
<div id="message" class="message" />
</div>
</body>
</html>