-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson2toml.html
More file actions
116 lines (99 loc) · 2.37 KB
/
json2toml.html
File metadata and controls
116 lines (99 loc) · 2.37 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
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JSON to TOML Converter</title>
<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>JSON → TOML Converter</h1>
<textarea id="jsonInput" placeholder="Paste your JSON here..."></textarea>
<div class="buttons">
<button onclick="showExample()">View Example</button>
<button onclick="clearAll()">Clear</button>
<button onclick="convertToToml()">Convert to TOML</button>
</div>
<div id="output"></div>
<script>
function showExample() {
const example = `{
"languages": [
"Python",
"JavaScript",
"Ruby"
],
"user": {
"name": "JohnDoe",
"age": 30,
"is_active": true
}
}`;
document.getElementById('jsonInput').value = example;
}
function clearAll() {
document.getElementById('jsonInput').value = '';
document.getElementById('output').textContent = '';
}
function convertToToml() {
const input = document.getElementById('jsonInput').value;
const output = document.getElementById('output');
try {
const obj = JSON.parse(input);
const tomlOutput = toml.dump(obj);
output.textContent = tomlOutput;
} catch (e) {
output.textContent = 'Error: ' + e.message;
}
}
</script>
</body>
</html>