Report the length of the JSON array at path
in key
key
is key to parse.
path
is JSONPath to specify. Default is root $
, if not provided. Returns null if the key
or path
do not exist.
JSON.ARRLEN
returns an array of integer replies, an integer for each matching value, each is the array's length, or nil
, if the matching value is not an array.
For more information about replies, see Redis serialization protocol specification.
Get lengths of JSON arrays in a document
Create a document for wireless earbuds.
{{< highlight bash >}} redis> JSON.SET item:2 $ '{"name":"Wireless earbuds","description":"Wireless Bluetooth in-ear headphones","connection":{"wireless":true,"type":"Bluetooth"},"price":64.99,"stock":17,"colors":["black","white"], "max_level":[80, 100, 120]}' OK {{< / highlight >}}
Find lengths of arrays in all objects of the document.
{{< highlight bash >}} redis> JSON.ARRLEN item:2 '$.[*]'
- (nil)
- (nil)
- (nil)
- (nil)
- (nil)
- (integer) 2
- (integer) 3 {{< / highlight >}}
Return the length of the max_level
array.
{{< highlight bash >}} redis> JSON.ARRLEN item:2 '$..max_level'
- (integer) 3 {{< / highlight >}}
Get all the maximum level values.
{{< highlight bash >}} redis> JSON.GET item:2 '$..max_level' "[[80,100,120]]" {{< / highlight >}}
JSON.ARRINDEX
| JSON.ARRINSERT