0

Using Redis v6 and RedisJSON v2.2.0.

Sample json:

[
        {
                "msg": "hello",
                "sql": "blah"
        }
]

I can successfully get the msg value by calling:

redisReply *reply = redisCommand(context, "JSON.GET sample-rj $.msg");

It returns:

["hello"]

However I would like the redis reply to not contain the surrounding brackets and double quotes.

Is that possible to turn off on the Redis/RedisJSON side or do I have to do post processing on the string value myself?

Thanks

Dan
  • 2,209
  • 3
  • 23
  • 44

1 Answers1

0

I ended up doing this:

redisReply *reply = redisCommand(context, "JSON.GET sample-rj $.msg");

    if(reply != NULL) {

        char *trimmedStr = reply->str + 2; //remove prefix ["
        trimmedStr[strlen(trimmedStr)-2] = '\0'; //remove suffix "]

        ap_rprintf(r, "<h2>redis key val is: %s!</h2>", trimmedStr);

        freeReplyObject(reply);
    }
Dan
  • 2,209
  • 3
  • 23
  • 44
  • It's just because you're using the RedisJSON API directly from Hiredis, in dedicated clients in other langues the array is being parsed to a native array. – Guy Korland Oct 23 '22 at 10:17