#include#include "json.hpp" using json = nlohmann::json; int main() { json j = true; std::cout << std::boolalpha << j.is_boolean() << std::endl; // true j = 42; std::cout << std::boolalpha << j.is_boolean() << std::endl; // false return 0; }
#includeThis example shows the usage of `IsBool` method of the `Value` class in rapidjson library to check whether the stored value is a boolean. The libraries used in the examples are nlohmann::json and rapidjson.#include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" using namespace rapidjson; int main() { Document doc; doc.Parse("{\"value\": false}"); Value& v = doc["value"]; std::cout << std::boolalpha << v.IsBool() << std::endl; // true return 0; }