Search code examples
arraysjsonredisenterprise

Enterprise Redis JSON.GET Syntax for JSONARRAY contains


I'am looking what functionalities that Redis Enterprise can offer, and came up with following questions. Content in JSON using JSON.Set

JSON.SET warehouse:1 $ '{
    "city": "Boston",
    "location": "42.361145, -71.057083",
    "inventory": [
        {   
            "id": 15970,
            "gender": "Men",
            "season":["Fall", "Winter"],
            "description": "Turtle Check Men Navy Blue Shirt",
            "price": 34.95
        },
        {
            "id": 59263,
            "gender": "Women",
            "season": ["Fall", "Winter", "Spring", "Summer"],
            "description": "Titan Women Silver Watch",
            "price": 129.99
        },
        {
            "id": 46885,
            "gender": "Boys",
            "season": ["Fall"],
            "description": "Ben 10 Boys Navy Blue Slippers",
            "price": 45.99
        }
    ]
}'

How to write JSON.GET warehouse:1 for "season" contains "Winter"


Solution

  • What you are looking for is a "contains" operation for JSONPath. At the moment, I don't believe this is possible. This isn't a limitation with Redis Enterprise or Redis Stack, this is a limitation of JSONPath itself.

    I did some googling and found some bits and bobs with proposed syntax for JSONPath to do this. However, nothing implemented yet.

    There might be a clever hack to get around this but I couldn't think of one. I would suggest that you check out the JSONPath docs for Redis, looking specifically at the filtering examples, and that you play around with what you can do with JSONPath with an online evaluator.