#ifndef UTILS_FUNCTIONS_HPP_
#define UTILS_FUNCTIONS_HPP_
#include <optional>
struct functions {
static inline std::string isNull(const nlohmann::json& str) {
return str.is_null() ? str.dump() : str.get<std::string>();
}
template<typename T>
static std::optional<T> testValue(const nlohmann::json& data, const std::vector<std::string>& keys) {
const nlohmann::json* current = &data;
for (const auto& key : keys) {
if (current->contains(key)) {
current = &(*current)[key];
} else {
return std::nullopt;
if constexpr (std::is_same_v<T, bool>) {
if (current->is_boolean()) {
return current->get<bool>();
} else if constexpr (std::is_same_v<T, int>) {
if (current->is_number_integer()) {
return current->get<int>();
} else if constexpr (std::is_same_v<T, double>) {
if (current->is_number_float()) {
return current->get<double>();
} else if constexpr (std::is_same_v<T, std::string>) {
if (current->is_string()) {
return current->get<std::string>();
};
#endif