@@ -217,6 +217,22 @@ jsonquery(values, 'sort()') // [2, 7, 9]
217
217
jsonquery(values, 'sort(get(), "desc")') // [9, 7, 2]
218
218
```
219
219
220
+
## reverse
221
+
222
+
Create a new array with the items in reverse order.
223
+
224
+
```text
225
+
reverse()
226
+
```
227
+
228
+
Example:
229
+
230
+
```js
231
+
const data = [1, 2, 3]
232
+
jsonquery(data, 'reverse()')
233
+
// [3, 2, 1]
234
+
```
235
+
220
236
## pick
221
237
222
238
Pick one or multiple properties or paths, and create a new, flat object for each of them. Can be used on both an object or an array.
@@ -255,10 +271,10 @@ jsonquery(item, 'pick(.price)') // 25
255
271
256
272
## map
257
273
258
-
Map over an array and apply the provided query to each of the items in the array.
274
+
Map over an array and apply the provided callback query to each of the items in the array.
259
275
260
276
```text
261
-
map(query)
277
+
map(callback)
262
278
```
263
279
264
280
Examples:
@@ -288,6 +304,60 @@ jsonquery(data, 'map(.price * .quantity)')
288
304
// 8.6
289
305
```
290
306
307
+
## mapObject
308
+
309
+
Map over an object, and create a new object with the entry `{ key, value }` returned by the callback for every input entry.
310
+
311
+
```text
312
+
mapObject(callback)
313
+
```
314
+
315
+
Example:
316
+
317
+
```js
318
+
const data = { "a": 2, "b": 3 }
319
+
jsonquery(data, `mapObject({
320
+
key: (.key + " times two"),
321
+
value: (.value * 2)
322
+
})`)
323
+
// {
324
+
// "a times two": 4,
325
+
// "b times two": 6
326
+
// }
327
+
```
328
+
329
+
## mapKeys
330
+
331
+
Map over an object, and create a new object with the keys returned by the callback having the value of the original key.
332
+
333
+
```text
334
+
mapKeys(callback)
335
+
```
336
+
337
+
Example:
338
+
339
+
```js
340
+
const data = { "a": 2, "b": 3 }
341
+
jsonquery(data, 'mapKeys("#" + get())')
342
+
// { "#a": 2, "#b": 3 }
343
+
```
344
+
345
+
## mapValues
346
+
347
+
Map over an object, and create a new object with the values updated by the return value of callback.
348
+
349
+
```text
350
+
mapValues(callback)
351
+
```
352
+
353
+
Example:
354
+
355
+
```js
356
+
const data = { "a": 2, "b": 3 }
357
+
jsonquery(data, 'mapValues(get() * 2)')
358
+
// { "a": 4, "b": 6 }
359
+
```
360
+
291
361
## groupBy
292
362
293
363
Group a list with objects grouped by the value of given path. This creates an object with the different properties as key, and an array with all items having that property as value.
@@ -416,6 +486,45 @@ const data2 = [[1, 2, [3, 4]]]
416
486
jsonquery(data2, 'flatten()') // [1, 2, [3, 4]]
417
487
```
418
488
489
+
## join
490
+
491
+
Concatenate array items into a string with an optional separator.
492
+
493
+
```text
494
+
join()
495
+
join(separator)
496
+
```
497
+
498
+
Example:
499
+
500
+
```js
501
+
const data = [
502
+
{ "name": "Chris", "age": 16 },
503
+
{ "name": "Emily", "age": 32 },
504
+
{ "name": "Joe", "age": 18 }
505
+
]
506
+
507
+
jsonquery(data, 'map(.name) | join(", ")')
508
+
// "Chris, Emily, Joe"
509
+
```
510
+
511
+
## split
512
+
513
+
Divide a string into an array substrings, separated by a separator.
514
+
515
+
```text
516
+
split()
517
+
split(separator)
518
+
```
519
+
520
+
Example:
521
+
522
+
```js
523
+
const data = "hi there how are you doing?"
524
+
jsonquery(data, 'split(" ")')
525
+
// ["hi", "there", "how", "are", "you", "doing?"]
526
+
```
527
+
419
528
## uniq
420
529
421
530
Create a copy of an array where all duplicates are removed.
@@ -479,7 +588,7 @@ jsonquery(data, 'limit(4)') // [1, 2, 3, 4]
479
588
480
589
## size
481
590
482
-
Return the size of an array.
591
+
Return the size of an array or the length of a string.
483
592
484
593
```text
485
594
size()
@@ -490,6 +599,7 @@ Examples:
490
599
```js
491
600
jsonquery([1, 2], 'size()') // 2
492
601
jsonquery([1, 2, 3, 4], 'size()') // 4
602
+
jsonquery("hello", 'size()') // 5
493
603
```
494
604
495
605
## sum
@@ -951,6 +1061,13 @@ Examples:
951
1061
const data = { "a": 6, "b": 2 }
952
1062
953
1063
jsonquery(data, '.a + .b') // 8
1064
+
1065
+
const user = {
1066
+
"firstName": "José",
1067
+
"lastName": "Carioca"
1068
+
}
1069
+
jsonquery(user, '(.firstName + " ") + .lastName')
1070
+
// "José Carioca"
954
1071
```
955
1072
956
1073
## subtract (`-`)
@@ -1069,3 +1186,34 @@ jsonquery({"a": 23.1345 }, 'round(.a)') // 23
1069
1186
jsonquery({"a": 23.1345 }, 'round(.a, 2)') // 23.13
1070
1187
jsonquery({"a": 23.1345 }, 'round(.a, 3)') // 23.135
1071
1188
```
1189
+
1190
+
## number
1191
+
1192
+
Parse the numeric value in a string into a number.
1193
+
1194
+
```text
1195
+
number(text)
1196
+
```
1197
+
1198
+
Examples:
1199
+
1200
+
```js
1201
+
jsonquery({"value": "2.4" }, 'number(.value)') // 2.4
1202
+
jsonquery("-4e3", 'number(get())') // -4000
1203
+
jsonquery("2,7,1", 'split(",") | map(number(get()))') // [2, 7, 1]
1204
+
```
1205
+
1206
+
## string
1207
+
1208
+
Format a number as a string.
1209
+
1210
+
```text
1211
+
string(number)
1212
+
```
1213
+
1214
+
Examples:
1215
+
1216
+
```js
1217
+
jsonquery({"value": 2.4 }, 'string(.value)') // "2.4"
1218
+
jsonquery(42, 'string(get())') // "42"
1219
+
```
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4