Unverified Commit 8deb9a4f authored by Yuta Hongo's avatar Yuta Hongo Committed by GitHub
Browse files

Stringify JSON key of --json option result (#10046)

About RESP3 an ordered collection of key-value pairs, keys and value can
be any other RESP3 type, but a key should be string in JSON spec.
parent 65a76357
...@@ -1192,8 +1192,18 @@ static sds cliFormatReplyJson(sds out, redisReply *r) { ...@@ -1192,8 +1192,18 @@ static sds cliFormatReplyJson(sds out, redisReply *r) {
case REDIS_REPLY_MAP: case REDIS_REPLY_MAP:
out = sdscat(out,"{"); out = sdscat(out,"{");
for (i = 0; i < r->elements; i += 2) { for (i = 0; i < r->elements; i += 2) {
out = cliFormatReplyJson(out, r->element[i]); redisReply *key = r->element[i];
if (key->type == REDIS_REPLY_STATUS ||
key->type == REDIS_REPLY_STRING ||
key->type == REDIS_REPLY_VERB) {
out = cliFormatReplyJson(out, key);
} else {
/* According to JSON spec, JSON map keys must be strings, */
/* and in RESP3, they can be other types. */
sds tmp = cliFormatReplyJson(sdsempty(), key);
out = sdscatrepr(out,tmp,sdslen(tmp));
sdsfree(tmp);
}
out = sdscat(out,":"); out = sdscat(out,":");
out = cliFormatReplyJson(out, r->element[i+1]); out = cliFormatReplyJson(out, r->element[i+1]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment