Files
screeps/douwco_hivemind/include/Tools/JsonTool.hpp
2025-08-23 18:15:27 +02:00

33 lines
706 B
C++

#ifndef DOUWCO_HIVEMIND_JSON_TOOLS_HPP
#define DOUWCO_HIVEMIND_JSON_TOOLS_HPP
#include <nlohmann/json.hpp>
#include <vector>
namespace DouwcoHivemind
{
template <typename T>
std::vector<T> jsonToVector(const nlohmann::json &json)
{
std::vector<T> vector;
for (const auto &item : json)
{
vector.emplace_back(item.get<T>());
}
return vector;
};
template <typename T>
nlohmann::json vectorToJson(const std::vector<T> &vector)
{
nlohmann::json json;
for (const auto &item : vector)
{
json.emplace_back(item);
}
return json;
};
}
#endif // DOUWCO_HIVEMIND_JSON_TOOLS_HPP