-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathjson-minifier.html
More file actions
193 lines (173 loc) · 7.53 KB
/
Copy pathjson-minifier.html
File metadata and controls
193 lines (173 loc) · 7.53 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON Minifier — DevDunia</title>
<meta name="description" content="Minify JSON data by removing all unnecessary whitespace. Free online JSON minifier tool for developers.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://devdunia.com/production/json-minifier.html">
<meta property="og:title" content="JSON Minifier — DevDunia">
<meta property="og:description" content="Minify JSON data by removing all unnecessary whitespace. Free online JSON minifier tool.">
<meta property="og:image" content="https://devdunia.com/images/logo.png">
<link rel="icon" type="image/png" href="images/logo.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="css/comic.css">
<link href="https://fonts.googleapis.com/css2?family=Bangers&family=Comic+Neue:wght@400;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
/* ---- TODO migrate: page-specific overrides, not yet centralized in css/comic.css ---- */
.masthead-logo-text { font-family: 'Bangers', cursive; font-size: 1.9rem; letter-spacing: 2px; color: #fff; text-shadow: 3px 3px 0 var(--ink); line-height: 1; }
.masthead-logo-text span { color: var(--yellow); }
.hero-text h1 { font-family: 'Bangers', cursive; font-size: 2.8rem; letter-spacing: 2px; color: var(--orange); -webkit-text-stroke: 1px var(--ink); text-shadow: 4px 4px 0 var(--ink); line-height: 1; text-transform: uppercase; }
.comic-textarea:focus { border-color: var(--orange); box-shadow: inset 3px 3px 0 rgba(255,140,66,.1); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-orange { background: var(--orange); color: #fff; }
.stats-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.stat-chip.chip-blue { background: var(--blue); color: #fff; }
.stat-chip.chip-green { background: var(--green); color: #fff; }
.stat-chip.chip-purple { background: var(--purple); color: #fff; }
.stat-chip.chip-orange { background: var(--orange); color: #fff; }
@media (max-width: 760px) {
.stats-row { gap: 6px; }
}
</style>
</head>
<body>
<div class="paper-overlay"></div>
<div data-masthead></div>
<div class="page-wrap">
<div data-tool-hero
data-title="JSON Minifier"
data-chapter="27"
data-category="Converters & Formatters"
data-icon="🗜"
data-desc="Squash your verbose, pretty-printed JSON into a tight, compact single line — strip every byte of whitespace and slash payload sizes!"
data-color="blue"
data-badges="SHRINK IT,VALIDATES JSON,CLIENT-SIDE,FREE"
data-badge-colors="orange,blue,green,purple">
</div>
<!-- MASTHEAD -->
<!-- HERO -->
<!-- INPUT PANEL -->
<div class="panel">
<div class="panel-header">
📥 PASTE YOUR JSON HERE
<span class="panel-tag">INPUT</span>
</div>
<div class="panel-body">
<div class="section-label">Formatted JSON Input</div>
<textarea id="json-input" class="comic-textarea" rows="8"
placeholder='Paste your pretty JSON here...'></textarea>
<div class="btn-row">
<button id="minify-btn" class="btn btn-orange">🗜 Minify!</button>
<button id="clear-btn" class="btn btn-danger">🗑 Clear</button>
</div>
<div id="error-bubble" class="error-bubble">
💥 <span id="error-msg">Invalid JSON!</span>
</div>
</div>
</div>
<!-- OUTPUT PANEL -->
<div class="panel" id="output-panel" style="display:none;">
<div class="panel-header">
📤 MINIFIED OUTPUT
<span class="panel-tag">OUTPUT</span>
</div>
<div class="panel-body">
<div class="section-label">Minified JSON</div>
<div class="output-wrap">
<textarea id="json-output" class="comic-textarea" rows="4" readonly></textarea>
<button id="copy-btn" class="copy-btn">📋 COPY</button>
</div>
<div class="stats-row">
<div class="stat-chip chip-blue">
<span class="stat-label">ORIGINAL</span>
<span id="stat-original">—</span>
</div>
<div class="stat-chip chip-green">
<span class="stat-label">MINIFIED</span>
<span id="stat-minified">—</span>
</div>
<div class="stat-chip chip-purple">
<span class="stat-label">SAVINGS</span>
<span id="stat-savings">—</span>
</div>
</div>
</div>
</div>
</div><!-- /page-wrap -->
<script>
(function() {
var inputEl = document.getElementById('json-input');
var outputEl = document.getElementById('json-output');
var minifyBtn = document.getElementById('minify-btn');
var clearBtn = document.getElementById('clear-btn');
var copyBtn = document.getElementById('copy-btn');
var outPanel = document.getElementById('output-panel');
var errBubble = document.getElementById('error-bubble');
var errMsg = document.getElementById('error-msg');
var statOrig = document.getElementById('stat-original');
var statMin = document.getElementById('stat-minified');
var statSave = document.getElementById('stat-savings');
function showError(msg) { errMsg.textContent = msg; errBubble.classList.add('show'); }
function hideError() { errBubble.classList.remove('show'); }
function formatBytes(n) {
if (n === 0) return '0 B';
var k = 1024, sizes = ['B','KB','MB','GB'];
var i = Math.floor(Math.log(n) / Math.log(k));
return parseFloat((n / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function minify() {
var input = inputEl.value.trim();
if (!input) { showError('Please enter some JSON data first!'); return; }
try {
var parsed = JSON.parse(input);
var minified = JSON.stringify(parsed);
outputEl.value = minified;
outPanel.style.display = 'block';
hideError();
var origBytes = new Blob([input]).size;
var minBytes = new Blob([minified]).size;
var savings = origBytes > 0 ? ((origBytes - minBytes) / origBytes * 100).toFixed(1) : '0';
statOrig.textContent = formatBytes(origBytes);
statMin.textContent = formatBytes(minBytes);
statSave.textContent = savings + '%';
} catch (error) {
showError('Invalid JSON: ' + error.message);
outPanel.style.display = 'none';
}
}
minifyBtn.addEventListener('click', minify);
clearBtn.addEventListener('click', function() {
inputEl.value = '';
outputEl.value = '';
outPanel.style.display = 'none';
hideError();
});
copyBtn.addEventListener('click', function() {
outputEl.select();
try { document.execCommand('copy'); } catch(e) {}
if (navigator.clipboard) navigator.clipboard.writeText(outputEl.value).catch(function(){});
var orig = copyBtn.textContent;
copyBtn.textContent = '✔ COPIED!';
copyBtn.style.background = 'var(--green)';
setTimeout(function() {
copyBtn.textContent = orig;
copyBtn.style.background = 'var(--ink)';
}, 1800);
});
inputEl.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { minify(); }
});
// Example on load
window.addEventListener('load', function() {
var ex = {"name":"DevDunia","description":"Your world of developer tools","tools":[{"name":"JSON Minifier","category":"Encoding/Decoding","popular":true}],"features":{"free":true,"offline":true,"simple":true}};
inputEl.value = JSON.stringify(ex, null, 2);
});
})();
</script>
<script src="masthead.js"></script>
<script src="hero-banner.js"></script>
<script src="author-card.js"></script>
</body>
</html>