mapleFU commented on code in PR #1829:
URL: https://github.com/apache/kvrocks/pull/1829#discussion_r1372266112
##########
src/types/json.h:
##########
@@ -23,10 +23,51 @@
#include <jsoncons/json.hpp>
#include <jsoncons/json_error.hpp>
#include <jsoncons_ext/jsonpath/json_query.hpp>
+#include <jsoncons_ext/jsonpath/jsonpath_error.hpp>
-#include "jsoncons_ext/jsonpath/jsonpath_error.hpp"
#include "status.h"
+class JsonPath {
+ public:
+ using JsonType = jsoncons::json;
+ using JsonPathExpression = jsoncons::jsonpath::jsonpath_expression<JsonType,
const JsonType &>;
+
+ static constexpr std::string_view ROOT_PATH = "$";
+
+ static StatusOr<JsonPath> BuildJsonPath(std::string_view path);
+
+ bool IsLegacy() const noexcept { return is_legacy_; }
+
+ std::string_view Path() const { return path_; }
+
+ bool IsRootPath() const { return Path() == ROOT_PATH; }
+
+ JsonType EvalJsonQuery(const JsonType &json_value) const {
+ return expression_.evaluate(const_cast<JsonType &>(json_value));
+ }
+
+ template <typename BinaryJsonFunction>
+ void EvalJsonReplace(JsonType &json_value, const BinaryJsonFunction
&callback) const {
+ auto wrapped_cb = [&callback](const std::string_view &path, const JsonType
&json) {
+ // Though JsonPath supports mutable reference,
`jsoncons::make_expression`
+ // only supports const reference, so const_cast is used as a workaround.
+ callback(path, const_cast<JsonType &>(json));
+ };
+ expression_.evaluate(json_value, wrapped_cb);
+ }
Review Comment:
https://github.com/danielaparker/jsoncons/discussions/466
@PragmaTwice The author says he will implement a mutable in next release.
Let me make this patch small and waiting for next release
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]