-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
206 lines (174 loc) · 4.82 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<!-- saved from url=(0049)http://bernhardhaeussner.de/odd/json-escape/#desc -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8">
<title>Escape for JSON and Javascript online tool</title>
<style>
* {padding:0;margin:0;}
body {background:#CCECF7;font-family:Arial,sans-serif;color:#5d5449;font-size:16px;}
.block {width:800px; margin: 0 auto;}
textarea,input {width:100%}
textarea {height:100px;}
p, h1 {margin:20px 0;}
h1 {font-size:40px;}
small {font-size:10px;color:#bbaa93;}
small a {color:#b6b2c8;}
.noJsError {color:#900;font-weight:bold;}
.jsEnabled .noJsError {display:none;}
.descDisabled .desc {display:none;}
@media (min-width:1200px) {
h1 {font-size:50px;}
.descDisabled .block {width:1100px;}
}
@media (min-width:1200px) and (min-height:700px) {
textarea {height:200px;}
}
@media (min-width:1200px) and (min-height:900px) {
textarea {height:300px;}
}
@media (max-width:400px) {
h1 {font-size:20px;}
.cont {padding:5px 10px;}
}
</style>
</head>
<body class=" jsEnabled">
<div class="cont">
<div class="block desc">
<h1>Escape for multiline JSON</h1>
<p>
This tool lets you convert a formatted
<abbr title="Javascirpt Object">JSON</abbr>
into multiline escaped concatenated version ready to paste in your js or java code.
Source code on <a href="https://github.com/szydan/json-escape">github</a>
<p class="noJsError">
You neeed Javascript enabled in your browser for this to work.
</p>
</div>
<div class="block" id="app">
<p>Normal (pretty printed json):<br>
<textarea id="normal">
{
"boolean": {
"clause": [
{
"occur": "SHOULD",
"twig": {
"descendant": [
{
"level": 2,
"node": {
"query": "xsd:string([10:00 TO *])",
"attribute": "fixedStartTime"
}
}
]
}
},
{
"occur": "SHOULD",
"twig": {
"descendant": [
{
"level": 3,
"node": {
"query": "xsd:string([10:00 TO *])",
"attribute": "minTime"
}
}
]
}
},
{
"occur": "SHOULD",
"twig": {
"descendant": [
{
"level": 2,
"node": {
"query": "xsd:string([* TO 12:00])",
"attribute": "fixedEndTime"
}
}
]
}
},
{
"occur": "SHOULD",
"twig": {
"descendant": [
{
"level": 3,
"node": {
"query": "xsd:string([* TO 12:00])",
"attribute": "maxTime"
}
}
]
}
}
]
}
}
</textarea></p>
<p><input type="button" value="↓ escape ↓" id="btnEscape"></p>
<p>Escaped & quoted & concatenated:<br>
<textarea id="jsonesc"></textarea>
</p>
</div>
<script>
function trim(s){
return s .replace(/^\s+|\s+$/g, '');
}
document.getElementById('btnEscape').onclick=function(){
var inp = document.getElementById('normal').value;
var inp = trim(inp);
var lines = inp.split("\n");
var outp = "var json = ";
for(var i = 0;i < lines.length;i++){
var line = lines[i];
if(line != ""){
outp += json_quote(lines[i]);
if(i != (lines.length-1)){
outp += "+\n";
}else{
outp += ";";
}
}
}
document.getElementById('jsonesc').value=outp;
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
};
function json_quote(string) {
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
</script></div>
<div class="block">
<p><small>
© Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
Created 2014 by <a href="">Szymon Danielczyk</a>.
based on <a href="http://bernhardhaeussner.de/">Bernhard Häussner</a>
<a href="http://bernhardhaeussner.de/odd/json-escape/">page</a>
Escaping code borrowed from Douglas Crockford's
<a
href="https://github.com/douglascrockford/JSON-js/blob/ad6079cbd8dc362a3cc42e1f97c01aa5ccd48bfe/json2.js#L211"
title="line 211 of file json2.js at ad6079cbd8 in JSON-js by douglascrockford on github">
JSON-js</a>.
</small></p>
</div>
</body></html>