JSON.GET - Amazon MemoryDB

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

JSON.GET

返回在一条或多条路径JSON上序列化的。

语法

JSON.GET <key> [INDENT indentation-string] [NEWLINE newline-string] [SPACE space-string] [NOESCAPE] [path ...]
  • 密钥(必填)— JSON 文档类型的密钥

  • INDENT/NEWLINE/SPACE(可选)— 控制返回JSON字符串的格式,即 “pretty print”。每个字符串的默认值都是空字符串。他们在任意组合中都可被覆盖。可以按任意顺序指定这些字符串。

  • NOESCAPE-可选,允许存在以实现传统兼容性,并且没有其他影响。

  • path(可选)— 零个或多个JSON路径,如果未给出任何路径,则默认为根路径。路径参数必须放在末尾。

Return

增强的路径语法:

如果给出了一条路径:

  • 返回值数组的序列化字符串。

  • 如果未选择值,则此命令会返回一个空数组。

如果给出了多条路径:

  • 返回一个字符串化JSON对象,其中每个路径都是一个键。

  • 如果混合了增强的路径语法和受限的路径语法,则结果符合增强的语法。

  • 如果路径不存在,则其相应的值为空数组。

示例

增强的路径语法:

127.0.0.1:6379> JSON.SET k1 . '{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}' OK 127.0.0.1:6379> JSON.GET k1 $.address.* "[\"21 2nd Street\",\"New York\",\"NY\",\"10021-3100\"]" 127.0.0.1:6379> JSON.GET k1 indent "\t" space " " NEWLINE "\n" $.address.* "[\n\t\"21 2nd Street\",\n\t\"New York\",\n\t\"NY\",\n\t\"10021-3100\"\n]" 127.0.0.1:6379> JSON.GET k1 $.firstName $.lastName $.age "{\"$.firstName\":[\"John\"],\"$.lastName\":[\"Smith\"],\"$.age\":[27]}" 127.0.0.1:6379> JSON.SET k2 . '{"a":{}, "b":{"a":1}, "c":{"a":1, "b":2}}' OK 127.0.0.1:6379> json.get k2 $..* "[{},{\"a\":1},{\"a\":1,\"b\":2},1,1,2]"

受限的路径语法:

127.0.0.1:6379> JSON.SET k1 . '{"firstName":"John","lastName":"Smith","age":27,"weight":135.25,"isAlive":true,"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021-3100"},"phoneNumbers":[{"type":"home","number":"212 555-1234"},{"type":"office","number":"646 555-4567"}],"children":[],"spouse":null}' OK 127.0.0.1:6379> JSON.GET k1 .address "{\"street\":\"21 2nd Street\",\"city\":\"New York\",\"state\":\"NY\",\"zipcode\":\"10021-3100\"}" 127.0.0.1:6379> JSON.GET k1 indent "\t" space " " NEWLINE "\n" .address "{\n\t\"street\": \"21 2nd Street\",\n\t\"city\": \"New York\",\n\t\"state\": \"NY\",\n\t\"zipcode\": \"10021-3100\"\n}" 127.0.0.1:6379> JSON.GET k1 .firstName .lastName .age "{\".firstName\":\"John\",\".lastName\":\"Smith\",\".age\":27}"