JSON.MGET

Usage:
JSON.MGET key [ key ... ] path
Complexity:
O(N) where N is the number of keys
Module:
valkey-json
Since module version:
1.0.0
ACL Categories:
@read, @fast, @json

Get serialized JSON objects from multiple document keys at the specified path. Return null for non-existent keys or JSON paths.

Examples

Enhanced path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021"}}'
OK
127.0.0.1:6379> JSON.SET k2 . '{"address":{"street":"5 main Street","city":"Boston","state":"MA","zipcode":"02101"}}'
OK
127.0.0.1:6379> JSON.SET k3 . '{"address":{"street":"100 Park Ave","city":"Seattle","state":"WA","zipcode":"98102"}}'
OK
127.0.0.1:6379> JSON.MGET k1 k2 k3 $.address.city
1) "[\"New York\"]"
2) "[\"Boston\"]"
3) "[\"Seattle\"]"

Restricted path syntax:

127.0.0.1:6379> JSON.SET k1 . '{"address":{"street":"21 2nd Street","city":"New York","state":"NY","zipcode":"10021"}}'
OK
127.0.0.1:6379> JSON.SET k2 . '{"address":{"street":"5 main Street","city":"Boston","state":"MA","zipcode":"02101"}}'
OK
127.0.0.1:6379> JSON.SET k3 . '{"address":{"street":"100 Park Ave","city":"Seattle","state":"WA","zipcode":"98102"}}'
OK

127.0.0.1:6379> JSON.MGET k1 k2 k3 .address.city
1) "\"New York\""
2) "\"Seattle\""
3) "\"Seattle\""

RESP2 Reply

  • Array reply: Array of Bulk Strings with size equal to the number of keys in the command.

    • Each element is either:

      • Bulk string reply: Serialized JSON as located by the path.

      • Nil reply: If the key does not exist, the path does not exist in the document, or the path is invalid.

  • Simple error reply: WRONGTYPE error if any specified key exists but is not a JSON key.

RESP3 Reply

  • Array reply: Array of Bulk Strings with size equal to the number of keys in the command.

    • Each element is either:

      • Bulk string reply: Serialized JSON as located by the path.

      • Null reply: If the key does not exist, the path does not exist in the document, or the path is invalid.

  • Simple error reply: WRONGTYPE error if any specified key exists but is not a JSON key.