JSON 的 JSON 格式。获取

语法
JSON.GET key [INDENT indent] [NEWLINE newline] [SPACE space] [path
  [path ...]]
可用:
Redis 堆栈 / JSON 1.0.0
时间复杂度:
O(N) 当 path 被评估为单个值时,其中 N 是值的大小,当 path 被评估为多个值时,O(N) ,其中 N 是键的大小

返回 at 的值pathJSON 序列化形式

例子

必需参数

key

是解析的关键。

可选参数

path

是 JSONPath 来指定。默认值为 root 。JSON 的 JSON 格式。GET 接受多个$path参数。

注意:

使用单个 JSONPath 时,匹配值的根是一个 JSON 字符串,其中包含序列化 JSON 值的顶级数组。 相反,传统路径返回单个值。

使用多个 JSONPath 参数时,匹配值的根是具有顶级对象的 JSON 字符串,每个对象值都是序列化 JSON 值的顶级数组。 相反,如果所有路径都是旧路径,则每个对象值都是一个序列化的 JSON 值。 如果有多个路径同时包含传统路径和 JSONPath,则返回的值符合 JSONPath 版本(值数组)。

INDENT

设置嵌套级别的缩进字符串。

NEWLINE

设置在每行末尾打印的字符串。

SPACE

设置放在 key 和 value 之间的字符串。

注意:

生成格式漂亮的 JSONredis-cli按照以下示例进行作:

~/$ redis-cli --raw
redis> JSON.GET myjsonkey INDENT "\t" NEWLINE "\n" SPACE " " path.to.value[1]

Return

JSON.GET returns a bulk string representing a JSON array of string replies. Each string is the JSON serialization of each JSON value that matches a path. Using multiple paths, JSON.GET returns a bulk string representing a JSON object with string values. Each string value is an array of the JSON serialization of each JSON value that matches a path. For more information about replies, see Redis serialization protocol specification.

Examples

Return the value at path in JSON serialized form

Create a JSON document.

redis> JSON.SET doc $ '{"a":2, "b": 3, "nested": {"a": 4, "b": null}}'
OK

With a single JSONPath (JSON array bulk string):

redis>  JSON.GET doc $..b
"[3,null]"

Using multiple paths with at least one JSONPath returns a JSON string with a top-level object with an array of JSON values per path:

redis> JSON.GET doc ..a $..b
"{\"$..b\":[3,null],\"..a\":[2,4]}"

See also

JSON.SET | JSON.MGET


RATE THIS PAGE
Back to top ↑