0

I want to fetch starting 10 records with specific keys in Redis JSON - {uuid,content} using JSON.GET.

I can fetch the 10 records and only one key using this command - JSON.GET blogs $.[0:10].uuid .

How do i fetch other keys?

Data -

[
    {
         "uuid" : "111111",
         "content" : "xxx",
         "somekey": "sss"
    },
    {
         "uuid" : "1222",
         "content" : "xxx",
         "somekey": "sss"
    }
]

Expected Data -

[
    {
         "uuid" : "111111",
         "content" : "xxx"
    },
    {
         "uuid" : "1222",
         "content" : "xxx",
    }
]
Suyash Jawale
  • 190
  • 2
  • 13
  • I'm not sure if it's clear what do you want to achieve here. Are you referring key as a JSON document? If so, you can use `JSON.MGET` to fetch multiple key for a given JSONPath (https://redis.io/commands/json.mget/). Or if you referring a single JSON, with multiple objects? For that you can try to use JSON Path Filters to match the condition. Such as `'?(@somekey=="sss")'` details here https://redis.io/docs/stack/json/path/#jsonpath-syntax – Adriano Amaral Apr 03 '23 at 15:03
  • blogs is a key which has the json value...like a python dictionary. – Suyash Jawale Apr 05 '23 at 14:00

1 Answers1

0

How about this:

JSON.SET blogs $ '[{"uuid" : "111111", "content" : "xxx","somekey": "sss"},{"uuid" : "1222","content" : "xxx","somekey": "sss"}]'
JSON.GET blogs '$[0:10]["uuid", "content"]'
["111111","xxx","1222","xxx"]
Lior Kogan
  • 19,919
  • 6
  • 53
  • 85
  • Pardon, posting late - The answer is great. But doesn't satisfy the usecase. – Suyash Jawale Apr 16 '23 at 10:08
  • @SuyashJawale this is the best you can do right now. When using the `["name”[,"name”]…]` JSONPath step - you won't retrieve the key names in the result. See also https://github.com/RedisJSON/RedisJSON/issues/955 – Lior Kogan Apr 16 '23 at 13:18