What's new in Valkey 9.0? Discover new features and improvements. Read the announcement.

JSON.GET

Get the serialized JSON at one or multiple paths.

Usage
JSON.GET key [INDENT/NEWLINE/SPACE] [NOESCAPE] [path ...]
Complexity
O(N) where N is the number of paths
Module
valkey-json
Since module version
1.0.0
ACL Categories
@read, @fast, @json

Get the serialized JSON at one or multiple paths.

Examples

Enhanced path syntax:

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]"

Restricted path syntax:

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}"

Replies

RESP2

  • For enhanced path syntax:
    • If one path is given:
    • If multiple paths are given:
      • Bulk string reply: Stringified JSON object, where each path is a key.
      • Result conforms to enhanced syntax if there are mixed enhanced and restricted path syntax.
      • Array reply: Empty array for paths that do not exist.
  • For restricted path syntax:

RESP3

  • For enhanced path syntax:
    • If one path is given:
    • If multiple paths are given:
      • Bulk string reply: Stringified JSON object, where each path is a key.
      • Result conforms to enhanced syntax if there are mixed enhanced and restricted path syntax.
      • Array reply: Empty array for paths that do not exist.
  • For restricted path syntax: