This library provides JMESPath procedures. JMESPath is defined on JMESPath.
The following example shows how to use the library:
(import (rnrs) (text json jmespath))
((jmespath "a") '#(("a" . "foo") ("b" . "bar") ("c" . "baz")))
foo
Returns a procedure takes one argument, which must be a vector representad JSON.
The given path must be a string which is a valid JMESPath, otherwise
raises &jmespath
.
This section describes conditions might be raised by the jmespath
procedure or the procedure returned by the jmespath
procedure.
The library doesn't export the condition type itself. (e.g. &jmespath
isn't exported from the library). However for the comprehensivity, we
also describe the hierarchy of the conditions here:
+ &error (standard R6RS error)
+ &jmespath
+ &jmespath:parse
+ &jmespath:expression
- expression
- argument
+ &jmespath:compile
+ &jmespath:runtime
The &jmespath
is the root condition. This condition itself won't be
raised.
The &jmespath:parse
is the condition raised by the parser. This means
either the given expression is lexically incorrect or grammartically incorrect.
The &jmespath:expression
is the base condition of both
&jmespath:compile
and &jmespath:runtime
. This condition itself
won't be raised.
The &jmespath:compile
is the condition raised by the compiler. This means
the parsed expression is syntatically incorrect.
The &jmespath:runtime
is the condition raised by the returned procedure.
This means evaluation error. For example, a string is passed to the avg
function.
Returns #t if the given obj is an instance of &jmespath
,
otherwise #f.
Returns #t if the given obj is an instance of &jmespath:parse
,
otherwise #f.
The &jmespath:parse
is a sub condition of &jmespath
.
Returns expression
field of the given jmespath-error.
The the given jmespath-error must be a sub condition of
&jmespath:expression
.
Returns arguments
field of the given jmespath-error.
The the given jmespath-error must be a sub condition of
&jmespath:expression
.
Returns #t if the given obj is an instance of &jmespath:compile
,
otherwise #f.
The &jmespath:compile
is a sub condition of &jmespath:expression
.
Returns #t if the given obj is an instance of &jmespath:runtime
,
otherwise #f.
The &jmespath:runtime
is a sub condition of &jmespath:expression
.
This library provides extra functions for usability.
Returns parent node of the given node. This function can be used like this:
((jmespath "*.bar.parent(@)") '#(("foo" . #(("bar" . 1)))))
'(#((bar . 1)))
A literal doesn't have a parent so returns null
.
((jmespath "parent(`{}`)") '#(("foo" . #(("bar" . 1)))))
'null
Returns unique elements of the given array. This function can be used like this:
((jmespath "unique(@)") '(1 2 1 2 3))
'(1 2 3)
It raises a &jmespath:runtime
if the give array is not an array.
Returns #t if the given number is an odd number. This function can be used like this:
((jmespath "is_odd(@)") '5)
#t
It raises a &jmespath:runtime
if the give number is not a number.
Returns #t if the given number is an even number. This function can be used like this:
((jmespath "is_even(@)") '5)
#t
It raises a &jmespath:runtime
if the give number is not a number.
Removes element from the given array/object if the _expr_returns true value.
The array/object must be an array or object.
The expr must be an expression reference.
The expr is executed in the context of the elements of array/object.
Means if the @
is passed to the expr, then the receiving
value is one of the elements of the array/object.
This function can be used like this:
((jmespath "remove(@, &odd(@))") '(1 2 3 4 5))
'(1 3 5)
It raises a &jmespath:runtime
if the give array/object is not
either an array or object, or if the given expr is not a function
reference.
Removes entries from the given object either if array/expr is an array of string and it contains the key of the entry or if array/expr is a function expression and returns true value.
The object must be an object.
This function can be used like this:
((jmespath "remove_entry(@, `[\"key2\"]`)") '#(("key" . 1)))
'#((key . 1))
((jmespath "remove_entry(@, &contains(`[\"key2\"]`, @))")
'#(("key" . 1) ("key2" . 2)))
'#((key . 1))
It raises a &jmespath:runtime
if the give object is not an object,
or if the given array/expr is not an array of string or function
reference.
Returns array of given arguments any.
((jmespath "array_of(`1`, `2`, `3`)") 'null)
'(1 2 3)