#include#include using json = nlohmann::json; int main() { json number = 5; json string = "hello"; std::cout << std::boolalpha; std::cout << "Is number numeric? " << number.is_number() << std::endl; std::cout << "Is string numeric? " << string.is_number() << std::endl; return 0; }
Is number numeric? true Is string numeric? false
#include#include using json = nlohmann::json; int main() { json array = { 1, 2, 3 }; json object = { {"name", "John"}, {"age", 30} }; std::cout << std::boolalpha; std::cout << "Is array numeric? " << array.is_number() << std::endl; std::cout << "Is object numeric? " << object.is_number() << std::endl; return 0; }
Is array numeric? false Is object numeric? falseIn this example, we create two more json values: an array and an object. Again, we use the is_number() function to determine whether each value is numeric or not. The output shows that neither the array nor the object is numeric. Package library: nlohmann/json