Back to Redis

JSON.TYPE

content/commands/json.type.md

latest2.4 KB
Original Source

Report the type of JSON value at path

Examples

Required arguments

<details open><summary><code>key</code></summary>

is key to parse.

</details>

Optional arguments

<details open><summary><code>path</code></summary>

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

</details>

Examples

{{< highlight bash >}} redis> JSON.SET doc $ '{"a":2, "nested": {"a": true}, "foo": "bar"}' OK redis> JSON.TYPE doc $..foo

  1. "string" redis> JSON.TYPE doc $..a
  2. "integer"
  3. "boolean" redis> JSON.TYPE doc $..dummy (empty array) {{< / highlight >}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Supported</span> | <span title="Supported">✅ Flexible & Annual</span> <span title="Supported">✅ Free & Fixed</nobr></span> | |

Return information

{{< multitabs id="json-type-return-info" tab1="RESP2" tab2="RESP3" >}}

With $-based path argument: [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of [bulk string replies]({{< relref "/develop/reference/protocol-spec#bulk-strings" >}}), where each element is the type of the matching value.

With .-based path argument: [Bulk string reply]({{< relref "/develop/reference/protocol-spec#bulk-strings" >}}) representing the type of the matching value.

-tab-sep-

With $-based path argument (default): [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of [array replies]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of [bulk string replies]({{< relref "/develop/reference/protocol-spec#bulk-strings" >}}), where each nested array contains the type of the matching value.

With .-based path argument: [Array reply]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of [bulk string replies]({{< relref "/develop/reference/protocol-spec#bulk-strings" >}}) representing the type of the matching value.

{{< /multitabs >}}

See also

[JSON.SET]({{< relref "commands/json.set/" >}}) | [JSON.ARRLEN]({{< relref "commands/json.arrlen/" >}})

  • [RedisJSON]({{< relref "/develop/data-types/json/" >}})
  • [Index and search JSON documents]({{< relref "/develop/ai/search-and-query/indexing/" >}})