You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`data` is the JSON document that will be queried, often an array with objects.
369
370
-`query` is a JSON document containing a JSON query, either the text format or the parsed JSON format.
370
371
-`options` is an optional object that can contain the following properties:
371
-
-`functions` is an optional map with custom function creators. A function creator has optional arguments as input and must return a function that can be used to process the query data. For example:
372
+
-`functions` is an optional map with function creators. A function creator has optional arguments as input and must return a function that can be used to process the query data. For example:
Note that configuring the option `functions` will overwrite the default functions. In order to extend the existing functions it is necessary to import the build-in functions and extend the custom `functions` object with themasin the example above.
381
390
382
391
If the parameters are not a static value but can be a query themselves, the function `compile` can be used to compile them. For example, the actual implementation of the function `filter` is the following:
383
392
384
393
```js
394
+
import { functions } from '@jsonquerylang/jsonquery'
395
+
385
396
const options = {
386
397
functions: {
398
+
// keep all built-in functions
399
+
...functions,
400
+
401
+
// overwrite function "filter" with our own implementation
387
402
// usage example: 'filter(.age > 20)'
388
403
filter: (predicate) => {
389
404
const_predicate=compile(predicate)
@@ -409,16 +424,17 @@ Here:
409
424
]
410
425
```
411
426
412
-
When extending the built-in operators with a custom operator, the built-in operators can be imported via `import { operators } from 'jsonquery'` and then extended by mapping over them and adding the custom operator to the group with the right precedence level, or adding a newprecedence level if needed.
427
+
When extending the built-in operators with a custom operator, the built-in operators can be imported via `import { operators } from '@jsonquerylang/jsonquery'` and then extended by mapping over them and adding the custom operator to the group with the right precedence level (see example below), or adding a newprecedence level if needed.
413
428
414
429
The defined operators can be used in a text query. Only operators with both a left and right hand side are supported, like `a == b`. They can only be executed when there is a corresponding function. For example:
415
430
416
431
```js
417
-
import { buildFunction, operators } from 'jsonquery'
432
+
import { buildFunction, functions, operators } from '@jsonquerylang/jsonquery'
418
433
419
434
const options = {
420
435
// Define a new function "notEqual".
421
436
functions: {
437
+
...functions,
422
438
notEqual: buildFunction((a, b) =>a!==b)
423
439
},
424
440
@@ -521,8 +537,12 @@ The function `buildFunction` is a helper function to create a custom function. I
521
537
The query engine passes the raw arguments to all functions, and the functions have to compile the arguments themselves when they are dynamic. For example:
0 commit comments