diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index cb1f2251e7..7361e36089 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3816,6 +3816,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); } + // see https://github.com/nlohmann/json/pull/2685#issuecomment-994015092 + template + reference operator[](T * (&key)[n]) + { + return operator[](static_cast(key)); + } + + template + const_reference operator[](T * (&key)[n]) const + { + return operator[](static_cast(key)); + } + /*! @brief access specified object element with default value diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 9ff85b2d85..e4e397565f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21383,6 +21383,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); } + // see https://github.com/nlohmann/json/pull/2685#issuecomment-994015092 + template + reference operator[](T * (&key)[n]) + { + return operator[](static_cast(key)); + } + + template + const_reference operator[](T * (&key)[n]) const + { + return operator[](static_cast(key)); + } + /*! @brief access specified object element with default value