#include #include #include #include #ifndef _JSON_HELPERS_H #define _JSON_HELPERS_H class JsonHelpers { public: template static std::vector jsonArrToVector(JsonArray& arr, std::function converter, const bool unique = true) { std::vector vec; for (size_t i = 0; i < arr.size(); ++i) { String strVal = arr.get(i); T convertedVal = converter(strVal); // inefficient, but everything using this is tiny, so doesn't matter if (!unique || std::find(vec.begin(), vec.end(), convertedVal) == vec.end()) { vec.push_back(convertedVal); } } return vec; } template static void vectorToJsonArr(JsonArray& arr, const std::vector& vec, std::function converter) { for (typename std::vector::const_iterator it = vec.begin(); it != vec.end(); ++it) { arr.add(converter(*it)); } } }; #endif