---
acl_categories:
- '@json'
- '@read'
- '@slow'
arguments:
- name: key
type: key
- name: path
optional: true
type: string
categories:
- docs
- develop
- stack
- oss
- rs
- rc
- oss
- kubernetes
- clients
complexity: O(1) when path is evaluated to a single value, O(N) when path is evaluated
to multiple values, where N is the size of the key
description: Returns the number of keys of the object at path
group: json
hidden: false
linkTitle: JSON.OBJLEN
module: JSON
railroad_diagram: /images/railroad/json.objlen.svg
since: 1.0.0
stack_path: docs/data-types/json
summary: Returns the number of keys of the object at path
syntax_fmt: JSON.OBJLEN key [path]
title: JSON.OBJLEN
---
Report the number of keys in the JSON object at `path` in `key`
[Examples](#examples)
## Required arguments
key
is key to parse. Returns `null` for nonexistent keys.
## Optional arguments
path
is JSONPath to specify. Default is root `$`. Returns `null` for nonexistant path.
## Examples
{{< highlight bash >}}
redis> JSON.SET doc $ '{"a":[3], "nested": {"a": {"b":2, "c": 1}}}'
OK
redis> JSON.OBJLEN doc $..a
1) (nil)
2) (integer) 2
{{< / highlight >}}
## Redis Software and Redis Cloud compatibility
| Redis
Software | Redis
Cloud | Notes |
|:----------------------|:-----------------|:------|
| ✅ Supported
| ✅ Flexible & Annual
✅ Free & Fixed | |
## Return information
{{< multitabs id="json-objlen-return-info"
tab1="RESP2"
tab2="RESP3" >}}
With `$`-based path argument: [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of [integer replies]({{< relref "/develop/reference/protocol-spec#integers" >}}) or [null replies]({{< relref "/develop/reference/protocol-spec#nulls" >}}), where each element is the number of keys in the object, or `null` if the matching value is not an object.
With `.`-based path argument: [Integer reply]({{< relref "/develop/reference/protocol-spec#integers" >}}) representing the number of keys in the object, or [null reply]({{< relref "/develop/reference/protocol-spec#nulls" >}}) if the matching value is not an object.
-tab-sep-
With `$`-based path argument (default): [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of [integer replies]({{< relref "/develop/reference/protocol-spec#integers" >}}) or [null replies]({{< relref "/develop/reference/protocol-spec#nulls" >}}), where each element is the number of keys in the object, or `null` if the matching value is not an object.
With `.`-based path argument: [Integer reply]({{< relref "/develop/reference/protocol-spec#integers" >}}) representing the number of keys in the object, or [null reply]({{< relref "/develop/reference/protocol-spec#nulls" >}}) if the matching value is not an object.
{{< /multitabs >}}
## See also
[`JSON.ARRINDEX`]({{< relref "commands/json.arrindex/" >}}) | [`JSON.ARRINSERT`]({{< relref "commands/json.arrinsert/" >}})
## Related topics
* [RedisJSON]({{< relref "/develop/data-types/json/" >}})
* [Index and search JSON documents]({{< relref "/develop/ai/search-and-query/indexing/" >}})