[フレーム]
Docs Pricing
Login Book a meeting Try Redis

JSON.ARRLEN

Syntax
JSON.ARRLEN key [path]
Available in:
Redis Open Source / JSON 1.0.0
Time complexity:
O(1) where path is evaluated to a single value, O(N) where path is evaluated to multiple values, where N is the size of the key
ACL categories:
@json, @read, @slow,

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.

Examples

Get lengths of JSON arrays in a document

Create a document for wireless earbuds.

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

Find lengths of arrays in all objects of the document.

redis> JSON.ARRLEN item:2 '$.[*]'
1) (nil)
2) (nil)
3) (nil)
4) (nil)
5) (nil)
6) (integer) 2
7) (integer) 3

Return the length of the max_level array.

redis> JSON.ARRLEN item:2 '$..max_level'
1) (integer) 3

Get all the maximum level values.

redis> JSON.GET item:2 '$..max_level'
"[[80,100,120]]"

Return information

With $-based path argument: Array reply of integer replies or null replies, where each element is the array length, or null if the matching value is not an array.

With .-based path argument: Integer reply representing the array length, or null reply if the matching value is not an array.

See also

JSON.ARRINDEX | JSON.ARRINSERT

RATE THIS PAGE
Back to top ↑

AltStyle によって変換されたページ (->オリジナル) /