diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index b97d6cbdfa..411fe55482 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -2538,7 +2538,7 @@ namespace detail { jsonpath_expression& operator=(jsonpath_expression&&) = default; template - typename std::enable_if::value,void>::type + typename std::enable_if::value,void>::type evaluate(const_reference instance, BinaryCallback callback, result_options options = result_options()) const { jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; @@ -2549,6 +2549,18 @@ namespace detail { expr_.evaluate(resources, instance, resources.root_path_node(), instance, f, options); } + template + typename std::enable_if::value,void>::type + evaluate_and_update(reference instance, BinaryCallback callback) const + { + jsoncons::jsonpath::detail::dynamic_resources resources{alloc_}; + auto f = [&callback](const json_location_type& path, reference val) + { + callback(path.to_string(), val); + }; + expr_.evaluate_with_replacement(resources, instance, resources.root_path_node(), instance, f); + } + Json evaluate(const_reference instance, result_options options = result_options()) const { if ((options & result_options::path) == result_options::path) @@ -2641,6 +2653,25 @@ namespace detail { return jsonpath_expression(alloc_set, std::move(resources), std::move(expr)); } + template + auto make_expression_for_update(const typename Json::string_view_type& path, + const jsoncons::jsonpath::custom_functions& funcs = jsoncons::jsonpath::custom_functions()) + { + using jsonpath_traits_type = jsoncons::jsonpath::detail::jsonpath_traits; + + using value_type = typename jsonpath_traits_type::value_type; + using reference = typename jsonpath_traits_type::reference; + using evaluator_type = typename jsonpath_traits_type::evaluator_type; + using path_expression_type = typename jsonpath_traits_type::path_expression_type; + using json_location_type = typename jsonpath_traits_type::json_location_type; + + auto static_resources = jsoncons::make_unique>(funcs); + evaluator_type evaluator; + auto expr = evaluator.compile(*static_resources, path); + + return jsoncons::jsonpath::jsonpath_expression(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr)); + } + } // namespace jsonpath } // namespace jsoncons