Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / resources / org / gvsig / expressionevaluator / functions / en / JSON_VALUE.description.html @ 45633

History | View | Annotate | Download (8.27 KB)

1
<p>JsonPath expressions always refer to a
2
JSON structure in the same way as XPath
3
expression are used in combination
4
with an XML document. The "root member
5
object" in JsonPath is always referred to
6
as <code>$</code> regardless if it is an
7
object or array.</p>
8
<p>JsonPath expressions can use the
9
dot–notation</p>
10
<p><code>$.store.book[0].title</code></p>
11
<p>or the bracket–notation</p>
12
<p><code>$['store']['book'][0]['title']</code></p>
13
<h2>Operators</h2>
14
<table>
15
<thead>
16
<tr>
17
<th align="left">Operator</th>
18
<th align="left">Description</th>
19
</tr>
20
</thead>
21
<tbody>
22
<tr>
23
<td align="left"><code>$</code></td>
24
<td align="left">The root element to
25
query. This starts all path
26
expressions.</td>
27
</tr>
28
<tr>
29
<td align="left"><code>@</code></td>
30
<td align="left">The current node
31
being processed by a filter
32
predicate.</td>
33
</tr>
34
<tr>
35
<td align="left"><code>*</code></td>
36
<td align="left">Wildcard. Available
37
anywhere a name or numeric are
38
required.</td>
39
</tr>
40
<tr>
41
<td align="left"><code>..</code></td>
42
<td align="left">Deep scan. Available
43
anywhere a name is required.</td>
44
</tr>
45
<tr>
46
<td align="left"><code>.&lt;name&gt;</code></td>
47
<td align="left">Dot-notated child</td>
48
</tr>
49
<tr>
50
<td align="left"><code>['&lt;name&gt;'
51
(, '&lt;name&gt;')]</code></td>
52
<td align="left">Bracket-notated child
53
or children</td>
54
</tr>
55
<tr>
56
<td align="left"><code>[&lt;number&gt;
57
(, &lt;number&gt;)]</code></td>
58
<td align="left">Array index or
59
indexes</td>
60
</tr>
61
<tr>
62
<td align="left"><code>[start:end]</code></td>
63
<td align="left">Array slice operator</td>
64
</tr>
65
<tr>
66
<td align="left"><code>[?(&lt;expression&gt;)]</code></td>
67
<td align="left">Filter expression. Expression must evaluate to a boolean value.</td>
68
</tr>
69
</tbody>
70
</table>
71
<h2>Functions</h2>
72
<p>Functions can be invoked at the tail end
73
of a path - the input to a function is the
74
output of the path expression.
75
The function output is dictated by the
76
function itself.</p>
77
<table>
78
<thead>
79
<tr>
80
<th align="left">Function</th>
81
<th align="left">Description</th>
82
<th align="left">Output type</th>
83
</tr>
84
</thead>
85
<tbody>
86
<tr>
87
<td align="left">min()</td>
88
<td align="left">Provides the min value of an array of numbers</td>
89
<td align="left">Double</td>
90
</tr>
91
<tr>
92
<td align="left">max()</td>
93
<td align="left">Provides the max value of an array of numbers</td>
94
<td align="left">Double</td>
95
</tr>
96
<tr>
97
<td align="left">avg()</td>
98
<td align="left">Provides the average value of an array of numbers</td>
99
<td align="left">Double</td>
100
</tr>
101
<tr>
102
<td align="left">stddev()</td>
103
<td align="left">Provides the standard deviation value of an array of numbers</td>
104
<td align="left">Double</td>
105
</tr>
106
<tr>
107
<td align="left">length()</td>
108
<td align="left">Provides the length of an array</td>
109
<td align="left">Integer</td>
110
</tr>
111
<tr>
112
<td align="left">sum()</td>
113
<td align="left">Provides the sum value of an array of numbers</td>
114
<td align="left">Double</td>
115
</tr>
116
<tr>
117
<td align="left">keys()</td>
118
<td align="left">Provides the property keys (An alternative for terminal tilde <code>~</code>)</td>
119
<td align="left"><code>Set&lt;E&gt;</code></td>
120
</tr>
121
<tr>
122
<td align="left">concat(X)</td>
123
<td align="left">Provides a concatinated version of the path output with a new item</td>
124
<td align="left">like input</td>
125
</tr>
126
<tr>
127
<td align="left">append(X)</td>
128
<td align="left">add an item to the json path output array</td>
129
<td align="left">like input</td>
130
</tr>
131
</tbody>
132
</table>
133
<h2>Filter Operators</h2>
134
<p>Filters are logical expressions used to
135
filter arrays. A typical filter would be <code>[?(@.age&gt; 18)]</code> where <code>@</code>
136
represents the current item being
137
processed. More complex filters can be
138
created with logical operators <code>&amp;&amp;</code>
139
and <code>||</code>. String literals must
140
be enclosed by single or double quotes (<code>[?(@.color
141
== 'blue')]</code> or <code>[?(@.color
142
== "blue")]</code>).</p>
143
<table>
144
<thead>
145
<tr>
146
<th align="left">Operator</th>
147
<th align="left">Description</th>
148
</tr>
149
</thead>
150
<tbody>
151
<tr>
152
<td align="left">==</td>
153
<td align="left">left is equal to right (note that 1 is not equal to '1')</td>
154
</tr>
155
<tr>
156
<td align="left">!=</td>
157
<td align="left">left is not equal to right</td>
158
</tr>
159
<tr>
160
<td align="left">&lt;</td>
161
<td align="left">left is less than right</td>
162
</tr>
163
<tr>
164
<td align="left">&lt;=</td>
165
<td align="left">left is less or equal to right</td>
166
</tr>
167
<tr>
168
<td align="left">&gt;</td>
169
<td align="left">left is greater than right</td>
170
</tr>
171
<tr>
172
<td align="left">&gt;=</td>
173
<td align="left">left is greater than or equal to right</td>
174
</tr>
175
<tr>
176
<td align="left">=~</td>
177
<td align="left">left matches regular expression [?(@.name =~ /foo.*?/i)]</td>
178
</tr>
179
<tr>
180
<td align="left">in</td>
181
<td align="left">left exists in right [?(@.size in ['S', 'M'])]</td>
182
</tr>
183
<tr>
184
<td align="left">nin</td>
185
<td align="left">left does not exists in right</td>
186
</tr>
187
<tr>
188
<td align="left">subsetof</td>
189
<td align="left">left is a subset of right [?(@.sizes subsetof ['S', 'M', 'L'])]</td>
190
</tr>
191
<tr>
192
<td align="left">anyof</td>
193
<td align="left">left has an intersection with right [?(@.sizes anyof ['M', 'L'])]</td>
194
</tr>
195
<tr>
196
<td align="left">noneof</td>
197
<td align="left">left has no intersection with right [?(@.sizes noneof ['M', 'L'])]</td>
198
</tr>
199
<tr>
200
<td align="left">size</td>
201
<td align="left">size of left (array or string) should match right</td>
202
</tr>
203
<tr>
204
<td align="left">empty</td>
205
<td align="left">left (array or string) should be empty</td>
206
</tr>
207
</tbody>
208
</table>
209
<h2>Path Examples</h2>
210
<p>Given the json</p>
211
<pre>
212
{
213
    "store": {
214
        "book": [
215
            {
216
                "category": "reference",
217
                "author": "Nigel Rees",
218
                "title": "Sayings of the Century",
219
                "price": 8.95
220
            },
221
            {
222
                "category": "fiction",
223
                "author": "Evelyn Waugh",
224
                "title": "Sword of Honour",
225
                "price": 12.99
226
            },
227
            {
228
                "category": "fiction",
229
                "author": "Herman Melville",
230
                "title": "Moby Dick",
231
                "isbn": "0-553-21311-3",
232
                "price": 8.99
233
            },
234
            {
235
                "category": "fiction",
236
                "author": "J. R. R. Tolkien",
237
                "title": "The Lord of the Rings",
238
                "isbn": "0-395-19395-8",
239
                "price": 22.99
240
            }
241
        ],
242
        "bicycle": {
243
            "color": "red",
244
            "price": 19.95
245
        }
246
    },
247
    "expensive": 10
248
}
249
</pre>
250

    
251
<table>
252
<thead>
253
<tr>
254
<th align="left">JsonPath</th>
255
<th align="left">Result</th>
256
</tr>
257
</thead>
258
<tbody>
259
<tr>
260
<td align="left">$.store.book[*].author</td>
261
<td align="left">The authors of all books</td>
262
</tr>
263
<tr>
264
<td align="left">$..author</td>
265
<td align="left">All authors</td>
266
</tr>
267
<tr>
268
<td align="left">$.store.*</td>
269
<td align="left">All things, both books and bicycles</td>
270
</tr>
271
<tr>
272
<td align="left">$.store..price</td>
273
<td align="left">The price of everything</td>
274
</tr>
275
<tr>
276
<td align="left">$..book[2]</td>
277
<td align="left">The third book</td>
278
</tr>
279
<tr>
280
<td align="left">$..book[-2]</td>
281
<td align="left">The second to last book</td>
282
</tr>
283
<tr>
284
<td align="left">$..book[0,1]</td>
285
<td align="left">The first two books</td>
286
</tr>
287
<tr>
288
<td align="left">$..book[:2]</td>
289
<td align="left">All books from index 0 (inclusive) until index 2 (exclusive)</td>
290
</tr>
291
<tr>
292
<td align="left">$..book[1:2]</td>
293
<td align="left">All books from index 1 (inclusive) until index 2 (exclusive)</td>
294
</tr>
295
<tr>
296
<td align="left">$..book[-2:]</td>
297
<td align="left">Last two books</td>
298
</tr>
299
<tr>
300
<td align="left">$..book[2:]</td>
301
<td align="left">Book number two from tail</td>
302
</tr>
303
<tr>
304
<td align="left">$..book[?(@.isbn)]</td>
305
<td align="left">All books with an ISBN number</td>
306
</tr>
307
<tr>
308
<td align="left">$.store.book[?(@.price&lt; 10)]</td>
309
<td align="left">All books in store cheaper than 10</td>
310
</tr>
311
<tr>
312
<td align="left">$..book[?(@.price&lt;= $['expensive'])]</td>
313
<td align="left">All books in store that are not "expensive"</td>
314
</tr>
315
<tr>
316
<td align="left">$..book[?(@.author=~ /.*REES/i)]</td>
317
<td align="left">All books matching regex (ignore case)</td>
318
</tr>
319
<tr>
320
<td align="left">$..*</td>
321
<td align="left">Give me every thing</td>
322
</tr>
323
<tr>
324
<td align="left">$..book.length()</td>
325
<td align="left">The number of books</td>
326
</tr>
327
</tbody>
328
</table>
329
<br>
330
<p>You can consult the documentation of the JSON_VALUE function of Oracle and SQL Server for more information.</p>