diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 1efb5049..28a7e8f3 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -122,6 +122,21 @@ class json_pointer return json_pointer(lhs) /= array_index; } + /*! + @brief create a new JSON pointer that is the parent of this JSON pointer + */ + json_pointer parent_pointer() const + { + if (empty()) + { + return *this; + } + + json_pointer res = *this; + res.pop_back(); + return res; + } + /*! @param[in] s reference token to be converted into an array index diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f3688a1c..15ec3b86 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -11932,6 +11932,21 @@ class json_pointer return json_pointer(lhs) /= array_index; } + /*! + @brief create a new JSON pointer that is the parent of this JSON pointer + */ + json_pointer parent_pointer() const + { + if (empty()) + { + return *this; + } + + json_pointer res = *this; + res.pop_back(); + return res; + } + /*! @param[in] s reference token to be converted into an array index