-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoml2json.html
More file actions
110 lines (92 loc) · 2.32 KB
/
toml2json.html
File metadata and controls
110 lines (92 loc) · 2.32 KB
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
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TOML to JSON Converter</title>
<!-- TOML parser -->
<script src="https://cdn.jsdelivr.net/npm/toml-js@0.0.8/lib/toml.min.js"></script>
<style>
body {
font-family: system-ui, sans-serif;
margin: 2rem;
background: #f5f5f5;
color: #222;
}
h1 {
margin-bottom: 1rem;
}
textarea {
width: 100%;
height: 220px;
padding: 0.75rem;
font-family: monospace;
font-size: 14px;
border-radius: 8px;
border: 1px solid #ccc;
box-sizing: border-box;
}
#output {
white-space: pre;
background: #fff;
padding: 0.75rem;
border-radius: 8px;
border: 1px solid #ccc;
margin-top: 1rem;
min-height: 220px;
font-family: monospace;
font-size: 14px;
}
.buttons {
margin-top: 1rem;
}
button {
padding: 0.6rem 1.2rem;
font-size: 15px;
border: none;
border-radius: 6px;
cursor: pointer;
background: #222;
color: #fff;
margin-right: 0.5rem;
}
button:hover {
background: #333;
}
</style>
</head>
<body>
<h1>TOML → JSON Converter</h1>
<textarea id="tomlInput" placeholder="Paste your TOML here..."></textarea>
<div class="buttons">
<button onclick="showExample()">View Example</button>
<button onclick="clearAll()">Clear</button>
<button onclick="convertToJson()">Convert to JSON</button>
</div>
<div id="output"></div>
<script>
function showExample() {
const example = `isActive = true
[employee]
firstName = "John"
lastName = "Doe"`;
document.getElementById('tomlInput').value = example;
}
function clearAll() {
document.getElementById('tomlInput').value = '';
document.getElementById('output').textContent = '';
}
function convertToJson() {
const input = document.getElementById('tomlInput').value;
const output = document.getElementById('output');
try {
const obj = toml.parse(input);
const json = JSON.stringify(obj, null, 2);
output.textContent = json;
} catch (e) {
output.textContent = 'Error: ' + e.message;
}
}
</script>
</body>
</html>