diff --git a/include/openPMD/auxiliary/JSON_internal.hpp b/include/openPMD/auxiliary/JSON_internal.hpp index dc72cffbdc..f419842b0b 100644 --- a/include/openPMD/auxiliary/JSON_internal.hpp +++ b/include/openPMD/auxiliary/JSON_internal.hpp @@ -76,10 +76,18 @@ namespace json * * @return nlohmann::json& */ - inline nlohmann::json &json() - { - return *m_positionInOriginal; - } + nlohmann::json &json(); + + /** + * @brief Access the underlying JSON value + * + * See args, first arg, used to distinguish this overload. + * + * @param path Index to some sub-expression. Shortcut for + * `tracingJSON[arg1][arg2][arg3].json()`. + * @return nlohmann::json& + */ + nlohmann::json &json(std::vector path); template TracingJSON operator[](Key &&key); diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index bdbd43325a..2946b047f0 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -1528,7 +1528,7 @@ adios2::Mode ADIOS2IOHandlerImpl::adios2AccessMode(std::string const &fullPath) if (m_config.json().contains("engine") && m_config["engine"].json().contains("access_mode")) { - auto const &access_mode_json = m_config["engine"]["access_mode"].json(); + auto const &access_mode_json = m_config.json({"engine", "access_mode"}); auto maybe_access_mode_string = json::asLowerCaseStringDynamic(access_mode_json); if (!maybe_access_mode_string.has_value()) diff --git a/src/IO/HDF5/ParallelHDF5IOHandler.cpp b/src/IO/HDF5/ParallelHDF5IOHandler.cpp index 00d5741457..e1192c8a9c 100644 --- a/src/IO/HDF5/ParallelHDF5IOHandler.cpp +++ b/src/IO/HDF5/ParallelHDF5IOHandler.cpp @@ -231,7 +231,7 @@ ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl( { return std::nullopt; } - auto const &val = vfd_json_config[key].json(); + auto const &val = vfd_json_config.json({key}); if (val.is_number_integer()) { return val.get(); @@ -250,7 +250,7 @@ ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl( { return std::nullopt; } - auto const &val = vfd_json_config[key].json(); + auto const &val = vfd_json_config.json({key}); if (auto str_val = json::asLowerCaseStringDynamic(val); str_val.has_value()) { diff --git a/src/auxiliary/JSON.cpp b/src/auxiliary/JSON.cpp index 7c96221026..8b758fe70e 100644 --- a/src/auxiliary/JSON.cpp +++ b/src/auxiliary/JSON.cpp @@ -60,6 +60,29 @@ TracingJSON::TracingJSON(ParsedConfig parsedConfig) std::move(parsedConfig.config), parsedConfig.originallySpecifiedAs} {} +nlohmann::json &TracingJSON::json() +{ + return *m_positionInOriginal; +} + +nlohmann::json &TracingJSON::json(std::vector paths) +{ + if (paths.empty()) + { + return json(); + } + auto it = paths.begin(); + auto end = paths.end(); + nlohmann::json *res = &m_positionInOriginal->operator[](*it); + auto subhandle = this->operator[](*it); + for (++it; it != end; ++it) + { + subhandle = subhandle[*it]; + res = &(*res)[*it]; + } + return *res; +} + nlohmann::json const &TracingJSON::getShadow() const { return *m_positionInShadow;