Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 1.77 KB

json.arrlen.md

File metadata and controls

72 lines (48 loc) · 1.77 KB

Report the length of the JSON array at path in key

Examples

Required arguments

key

is key to parse.

Optional arguments

path

is JSONPath to specify. Default is root $, if not provided. Returns null if the key or path do not exist.

Return

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.

Examples

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 '$.[*]'

  1. (nil)
  2. (nil)
  3. (nil)
  4. (nil)
  5. (nil)
  6. (integer) 2
  7. (integer) 3 {{< / highlight >}}

Return the length of the max_level array.

{{< highlight bash >}} redis> JSON.ARRLEN item:2 '$..max_level'

  1. (integer) 3 {{< / highlight >}}

Get all the maximum level values.

{{< highlight bash >}} redis> JSON.GET item:2 '$..max_level' "[[80,100,120]]" {{< / highlight >}}

See also

JSON.ARRINDEX | JSON.ARRINSERT

Related topics