-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
275 lines (244 loc) · 7.44 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html>
<head>
<title>GJSON Playground</title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/hack-font@3/build/web/hack.css">
<script src="wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
WebAssembly.instantiateStreaming(fetch("gjson.wasm"), go.importObject).then((result) => {
go.run(result.instance);
});
</script>
<style>
* {
/* box-sizing: content-box; */
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #a7b2bb;
color: rgba(39,40,34,0.80);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 17px;
}
.contents {
width: 90%;
margin: 0 auto;
}
#path {
display: block;
width: 100%;
max-width: 1000px;
border-radius: 15px;
background-color: #272822;
border: 0;
color: #dfdfde;
line-height: 50px;
padding: 0 25px;
font-size: 15px;
font-family: Hack, monospace;
outline: none;
box-shadow: 0px 15px 15px rgba(0,0,0,0.3);
margin: 10px auto;
}
#input, #output {
display: block;
width: 100%;
max-width: 1000px;
border-radius: 15px;
background-color: #272822;
border: 0;
padding: 25px;
color: #dfdfde;
font-size: 15px;
font-family: Hack, monospace;
outline: none;
box-shadow: 0px 15px 15px rgba(0,0,0,0.3);
resize: vertical;
margin: 10px auto;
word-wrap:unset;
}
#input {
height: 300px;
}
#output {
height: 150px;
}
.top {
display: block;
margin: 40px auto 40px auto;
text-align: center;
}
.top .logo {
position: relative;
left: -2px;
display: block;
margin: 0 auto 5px auto;
}
.top .sub {
color: #272822;
font-size: 32px;
font-weight: 900;
margin: 0 auto 0 auto;
}
.bottom {
display: block;
max-width: 800px;
margin: 40px auto 40px auto;
}
.bottom pre{
background: rgba(0,0,0,0.10);
padding: 20px;
border-radius: 6px;
font-family: Hack, monospace;
font-size: 15px;
}
.bottom p{
text-align: center;
}
.bottom h2, .bottom h3{
text-align: center;
color: #272822;
}
.octocat {
margin-top: 20px;
opacity: 0.82;
}
.example {
overflow: auto;
}
a {
color: black
}
</style>
</head>
<body>
<div class="contents">
<div class="top">
<img src="logo.png" height="60" class="logo">
<div class="sub">PLAYGROUND</div>
<p>GJSON provides a fast and simple way to search a JSON document.</p>
</div>
<div><input type="text" value="name.last" id="path"
data-gramm_editor="false" spellcheck="false" autocomplete="off"></div>
<div>
<textarea id="input"
data-gramm_editor="false" spellcheck="false" autocomplete="off">
{
"name": {"first": "Tom", "last": "Anderson"},
"age":37,
"children": ["Sara","Alex","Jack"],
"fav.movie": "Deer Hunter",
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
}
</textarea>
</div>
<div>
<textarea id="output" readonly
data-gramm_editor="false" spellcheck="false" autocomplete="off"
></textarea>
</div>
<div class="bottom">
<h3>EXAMPLES</h3>
<pre class="example">
name.last >> "Anderson"
age >> 37
children >> ["Sara","Alex","Jack"]
children.# >> 3
children.1 >> "Alex"
child*.2 >> "Jack"
c?ildren.0 >> "Sara"
fav\.movie >> "Deer Hunter"
friends.#.first >> ["Dale","Roger","Jane"]
friends.1.last >> "Craig"</pre>
<p>
Query an array for the first match by using #(...),
or find all matches with #(...)#.
Queries support the ==, !=, <, <=, >, >= comparison operators and
the simple pattern matching % operator.
</p>
<pre class="example">
friends.#(last=="Murphy").first >> "Dale"
friends.#(last=="Murphy")#.first >> ["Dale","Jane"]
friends.#(age>45)#.last >> ["Craig","Murphy"]
friends.#(first%"D*").last >> "Murphy"
friends.#(nets.#(=="fb"))#.first >> ["Dale","Roger"]</pre>
<p>
</p>
<p>
Use the selectors syntax to join multiple paths into a new JSON document.
</p>
<pre class="example">
{name.first,age,"murphys":friends.#(last="Murphy")#.first}
[name.first,age,children.0]</pre>
<p>
Use modifiers to modify the json. There are currently the following built-in modifiers:
<ul>
<li><b>@reverse</b>: Reverse an array or the members of an object.</li>
<li><b>@ugly</b>: Remove all whitespace from JSON.</li>
<li><b>@pretty</b>: Make the JSON more human readable.</li>
<li><b>@this</b>: Returns the current element. It can be used to retrieve the root element.</li>
<li><b>@valid</b>: Ensure the json document is valid.</li>
<li><b>@flatten</b>: Flattens an array.</li>
<li><b>@join</b>: Joins multiple objects into a single object.</li>
<li><b>@keys</b>: Returns an array of keys for an object.</li>
<li><b>@values</b>: Returns an array of values for an object.</li>
</ul>
</p>
<pre class="example">
children.@reverse >> ["Jack","Alex","Sara"]
children.@reverse.0 >> "Jack"
{name.first,"murphys":friends.0}.@pretty >> <i>beautiful JSON</i>
{name.first,"murphys":friends.0}.@ugly >> <i>compact JSON</i>
[@this].#(age>35).name.last >> "Anderson"</pre>
<p>
For more information, please see the <a href="https://github.com/tidwall/gjson">GJSON project</a>
and the <a href="https://github.com/tidwall/gjson/blob/master/SYNTAX.md">GJSON syntax</a>.
</p>
<p>
<br>
<br>
This page is open source at
<a href="https://github.com/tidwall/gjson-play">tidwall/gjson-play</a>.
<br>
<a href="https://github.com/tidwall/gjson"><img class="octocat"
src="octocat.png" height="40" border="0"></a>
</p>
</div>
</div>
<script>
var prev_json = null;
var prev_input = null;
document.getElementById("input").value =
document.getElementById("input").value.trim() + "\n";
window.setInterval(function() {
if (!window.gjsonGet) {
return;
}
var json = document.getElementById("input").value;
var path = document.getElementById("path").value;
if (json != prev_json || path != prev_path) {
var res = window.gjsonGet(json, path);
document.getElementById("output").value = res;
prev_json = json;
prev_path = path;
}
}, 50)
</script>
</body>
</html>