-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
160 lines (154 loc) · 6.86 KB
/
Copy pathindex.html
File metadata and controls
160 lines (154 loc) · 6.86 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
<meta content="width=device-width, initial-scale=1, minimum-scale=1.0, shrink-to-fit=no" name="viewport" />
<meta property="og:title" content="json_minifyer" />
<meta property="og:type" content="Tool" />
<meta property="og:url" content="https://mklhx.github.io/json_minifyer/" />
<!-- <meta property="og:image" content="https://mklhx.github.io/json_minifyer/" /> -->
<meta content="javascript json minifiyer tool" name="keywords">
<meta content="json_minifyer - online open source minifyer for json files" property="og:description" />
<meta content="json_minifyer - online open source minifyer for json files" name="description">
<meta content="json_minifyer" property="og:site_name" />
<link rel="canonical" href="https://mklhx.github.io/json_minifyer/" />
<script type='application/ld+json'>
{
"@context":"https://schema.org",
"@type":"Tool",
"@id":"json_minifyer",
"url":"https://mklhx.github.io/json_minifyer/",
"sameAs":[
"https://mklhx.github.io/json_minifyer/"
],
"name":"Boot4Modal.js"
}
</script>
<link rel="icon" href="favicon.ico" />
<meta name="google-site-verification" content="w9nDIcmAPerycr7DcYGAEOJiA3SW7eStM_Wx4pT50WY" />
<title>json_minifyer - online free json file minifyer tool</title>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://use.fontawesome.com/releases/v5.11.2/css/all.min.css" />
</head>
<body class="container-fluid bg-light">
<header class="row no-gutters justify-content-center">
<div class="col-12 text-center">
<h1>Welcome to Json Minifyer!<a href="#json_minifyer" class="text-dark h5"><i class="fas fa-link fa-1x"></i></a></h1>
<h2 class="text h4">
This is a huge free online tool to minifying json string!
</h2>
</div>
</header>
<main class="row no-gutters justify-content-center mt-5">
<!-- <style>
iframe {
min-height: 100vh !important;
}
</style>
<script async src="https://jsfiddle.net/MkLHX/2kmt093n/embed/result,js,html/dark/"></script> -->
<div class="col-12 col-md-8 col-lg-6 mx-auto text-center">
<h3>Input json formated string</h3>
<textarea class="shadow border-0 col" id="input" rows="25" cols="80" width="100%" height="100%"></textarea>
</div>
<div class="w-100"></div>
<div class="col-12 col-md-8 col-lg-6 mx-auto text-center">
<ul class="list-unstyled">
<li class="list-item">json length: <span id="inJsonLen">0</span></li>
</ul>
</div>
<div class="w-100"></div>
<div class="col-12 col-md-8 col-lg-6 mx-auto text-center">
<h3>Output json minified</h3>
<textarea class="shadow border-0 col" id="output" rows="3" cols="80" wrap="off"></textarea>
<button type="button" id="copy" class="bg-transparent border-0" style="display: none;"><i class="far fa-copy fa-2x"></i></button>
</div>
<div class="w-100"></div>
<div class="col-12 col-md-8 col-lg-6 mx-auto text-center">
<ul class="list-unstyled">
<li class="list-item">json length: <span id="outJsonLen">0</span></li>
</ul>
</div>
<div class="col-12 text-center align-self-center my-5">
<button type="button" id="btnBackSlashes" class="btn btn-info btn-lg">add escape backslashes</button>
<button type="button" id="btnNoBackSlashes" class="btn btn-info btn-lg" style="display: none;">remove backslashes</button>
</div>
</main>
<footer class="row no-gutters justify-content-center">
<div class="col-12 bg-light text-secondary text-center align-self-center">
<ul id="about" class="list-inline">
<li class="list-inline-item">made with <i class="fas fa-heart text-danger"></i> by <a href="https://github.com/MkLHX">MkLHX</a></li>
</ul>
</div>
</footer>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://use.fontawesome.com/releases/v5.11.2/js/all.js"></script>
<script>
let input = document.getElementById('input');
let output = document.getElementById('output');
let copy = document.getElementById('copy');
let btnBackSlashes = document.getElementById('btnBackSlashes');
let btnNoBackSlashes = document.getElementById('btnNoBackSlashes');
let inJsonLen = document.getElementById('inJsonLen');
let outJsonLen = document.getElementById('outJsonLen');
const minifyer = () => {
if (input.value.length > 0) {
let jsonObject;
inJsonLen.innerHTML = input.value.length;
try {
jsonObject = JSON.parse(input.value);
//show json look pretty
input.value = JSON.stringify(jsonObject, null, 4);
btnBackSlashes.style.display = 'inline';
} catch (e) {
alert(e);
btnBackSlashes.style.display = 'none';
btnNoBackSlashes.style.display = 'none';
}
let minified = JSON.stringify(jsonObject, null, 0)
output.value = minified;
outJsonLen.innerHTML = minified.length;
} else {
output.value = '';
}
};
input.addEventListener('keyup', () => {
setTimeout(() => { minifyer(); }, 1000);
});
btnBackSlashes.addEventListener('click', () => {
if (output.value.length > 0) {
let value = output.value.replace(/\"/g, '\\"');
output.value = '';
output.value = value;
copy.style.display = 'inline';
btnNoBackSlashes.style.display = 'inline';
btnBackSlashes.style.display = 'none';
} else {
alert('output cannot be empty to add escape backslash');
}
});
document.getElementById('btnNoBackSlashes').addEventListener('click', () => {
if (output.value.length > 0) {
let value = output.value.replace(/\\"/g, '\"');
output.value = '';
output.value = value;
btnBackSlashes.style.display = 'inline';
btnNoBackSlashes.style.display = 'none';
} else {
alert('output cannot be empty to add escape backslash');
}
});
document.getElementById('copy').addEventListener('click', () => {
if (output.value.length > 0) {
output.select();
document.execCommand("copy");
} else {
alert('cannot copy empty output');
}
});
</script>
</body>
</html>