Skip to content

Commit

Permalink
feat: allow querying of json objects stored as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
romange committed Jan 3, 2025
1 parent 6e9409c commit 652ea15
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/server/json_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,29 @@ bool LegacyModeIsEnabled(const std::vector<std::pair<std::string_view, WrappedJs

OpResult<std::string> OpJsonGet(const OpArgs& op_args, string_view key,
const JsonGetParams& params) {
OpResult<JsonType*> result = GetJson(op_args, key);
RETURN_ON_BAD_STATUS(result);
auto it = op_args.GetDbSlice().FindReadOnly(op_args.db_cntx, key).it;
if (!IsValid(it))
return OpStatus::KEY_NOTFOUND;

const JsonType* json_ptr = nullptr;
JsonType json;
if (it->second.ObjType() == OBJ_JSON) {
json_ptr = it->second.GetJson();
} else if (it->second.ObjType() == OBJ_STRING) {
string tmp;
it->second.GetString(&tmp);
auto parsed_json = ShardJsonFromString(tmp);
if (!parsed_json) {
return OpStatus::WRONG_TYPE;
}
json.swap(*parsed_json);
json_ptr = &json;
} else {
return OpStatus::WRONG_TYPE;
}

const auto& paths = params.paths;
const JsonType& json_entry = *(result.value());
const JsonType& json_entry = *json_ptr;

if (paths.empty()) {
// this implicitly means that we're using . which
Expand Down

0 comments on commit 652ea15

Please sign in to comment.