{
  "schema_version": 2,
  "id": "commands/json.objlen",
  "title": "JSON.OBJLEN",
  "url": "https://redis.io/docs/latest/commands/json.objlen/",
  "summary": "Returns the number of keys in JSON objects at the paths matching a given path expression",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:47:58+01:00",
  "page_type": "content",
  "content_hash": "ea7d92056bcbb41d5bcaacbf1ac4ad91e7ff66b081849a624ed64e0a10e56c7b",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Returns the number of keys in JSON objects at the paths matching a given path expression.\n\n> [!NOTE]\n> A JSON object is a structure within a JSON document that contains an unordered set of key-value pairs (also called name-value pairs). Do not confuse Redis keys with JSON object keys.\n\n[Examples](#examples)"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary> \n\nis a Redis key storing a value of type JSON.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>path</code></summary> \n\nis either \n\n- A JSONPath expression\n  - The root \"`$`\", or any string that starts with \"`$.`\" or \"`$[`\".\n  - Resolves to all matching locations in `key`.\n- A legacy path expression \n  - Any string that does not match the JSONPath syntax above.\n  - Allow the leading \"`.`\" to be omitted (for example, \"`name`\" and \"`.name`\" are equivalent).\n  - Resolves to only the first matching location in `key`.\n\nDefault: \"`.`\" (legacy path pointing to the root of the document).\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> JSON.SET doc $ '{\"a\":[3], \"nested\": {\"a\": {\"b\":2, \"c\": 1}}}'\nOK\nredis> JSON.OBJLEN doc $..a\n1) (nil)\n2) (integer) 2"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Supported</span><br /> | <span title=\"Supported\">&#x2705; Flexible & Annual</span><br /><span title=\"Supported\">&#x2705; Free & Fixed</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nIf `path` is a JSONPath expression:\n\n- A [simple error](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) if `key` does not exist.\n- An empty [array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays) if `path` has no matches.\n- An [array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays) where each array element corresponds to one match:\n  - [`nil`](https://redis.io/docs/latest/develop/reference/protocol-spec#null-bulk-strings) if the match is not an object.\n  - An [integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): the number of keys in the object.\n\nIf `path` is a legacy path expression:\n\n- [`nil`](https://redis.io/docs/latest/develop/reference/protocol-spec#null-bulk-strings) if `key` does not exist.\n- [`nil`](https://redis.io/docs/latest/develop/reference/protocol-spec#null-bulk-strings) if `path` has no matches.\n- A [simple error](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) if the first match is not an object.\n- An [integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): the number of keys in the first match.\n\n**RESP3:**\n\nIf `path` is a JSONPath expression:\n\n- A [simple error](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) if `key` does not exist.\n- An empty [array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays) if `path` has no matches.\n- An [array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays) where each array element corresponds to one match:\n  - [`nil`](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls) if the match is not an object.\n  - An [integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): the number of keys in the object.\n\nIf `path` is a legacy path expression:\n\n- [`nil`](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls) if `key` does not exist.\n- [`nil`](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls) if `path` has no matches.\n- A [simple error](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) if the first match is not an object.\n- An [integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): the number of keys in the first match."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`JSON.OBJKEYS`](https://redis.io/docs/latest/commands/json.objkeys)"
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "* [The JSON data type](https://redis.io/docs/latest/develop/data-types/json)\n* [JSONPath](https://redis.io/docs/latest/develop/data-types/json/path)\n* [Index and search JSON documents](https://redis.io/docs/latest/develop/ai/search-and-query/indexing)"
    }
  ],
  "examples": []
}
