Mercurial > minori
view include/core/json.h @ 175:9b10175be389
dep/json: update to v3.11.3
anime/db: save anime list to database, very much untested and likely won't work as intended
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 30 Nov 2023 13:52:26 -0500 |
parents | f88eda79c60a |
children | bc1ae1810855 |
line wrap: on
line source
#ifndef __core__json_h #define __core__json_h #include "json/json.hpp" namespace JSON { template<typename T = std::string> T GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def) { if (json.contains(ptr) && json[ptr].is_string()) return json[ptr].get<T>(); else return def; } template<typename T = int> T GetNumber(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def = 0) { if (json.contains(ptr) && json[ptr].is_number()) return json[ptr].get<T>(); else return def; } template<typename T = std::vector<std::string>> T GetArray(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def = 0) { if (json.contains(ptr) && json[ptr].is_array()) return json[ptr].get<T>(); else return def; } nlohmann::json GetValue(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr); bool GetBoolean(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, bool def = false); } // namespace JSON #endif // __core__json_h