The operators in this section are valid for maps.
Note: in addition to these operators, there is a membership infix operator that works on arrays and maps.
Many of the following operators take an argument that is a hash path. A hash path is an array whose elements represent the key values (for a map) or array indices of a path from the root of a complex data structure to the element of interest. For example, consider the following data structure:
The hash path
["foo", "bar"] references the following map inside the data structure:
delete() operator takes a hash path argument designating the member of the original data structure that should be deleted. The
delete() operator returns a new data structure with the specified member deleted. If the path is invalid, nothing is deleted and the new data structure is identical to the original. For example:
encode() operator returns a string containing the JSON representation of the data structure to which it is applied. For example:
encode() operator takes an optional map as an argument containing options for encoding.
|canonical||true, false||print keys in sorted order (creates canonical string)|
|pretty||true, false||pretty prints the encoding (newlines and indents) if true|
filter() operator takes a function as its only argument and returns a map. The new map contains any members of the original map for which the function evaluates to true. The function given as the argument must take two arguments and return a Boolean value. The function is applied to the key and value of each member of the map in turn. The number of elements in the new map will be less than or equal to the length of the original map. For example:
keys() operator returns the keys of the map to which it is applied. Without an argument, the keys at the top level of the map are returned. The operator also accepts a hash path argument. For example:
map() operator returns a map that contains the results of applying the function given as the operator's argument to each key-value pair from the original map. The function given as an argument must take two arguments: the first will be the value and the second the key. The result will be a map with the same keys, each key mapped to the result of the function. The length of the resulting map will be equal to the length of the target map. For example:
put() operator takes two arguments: a hash path and a new element to be inserted. The element must itself be a map. The result is a new data a structure with the element inserted at the location specified by the hash path. If the path specifies a location that does not exist, it will be created. If the location already has a value, it will be replaced by the new element. For example:
If the first argument is missing (i.e. there is only one argument) then the path is take to be the root and the item is put at the root level of the map:
values() operator returns the values of the map to which it is applied. Without an argument, the values at the top level of the map are returned. The operator also accepts a hash path argument. For example: