#include "json.hpp" using json = nlohmann::json; int main() { json arr = {1, 2, 3, 4, 5}; std::cout << "Array size: " << arr.size() << std::endl; return 0; }
#include "json.hpp" using json = nlohmann::json; int main() { json obj = {{"name", "Alice"}, {"age", 25}, {"city", "New York"}}; std::cout << "Object size: " << obj.size() << std::endl; return 0; }
#include "json.hpp" using json = nlohmann::json; int main() { json data = { {"name", "Bob"}, {"age", 30}, {"address", { {"street", "Main St"}, {"city", "Boston"}, {"state", "MA"} }}, {"friends", { {"Alice", {"age", 27}}, {"Charlie", {"age", 31}}, {"Dave", {"age", 29}} }} }; std::cout << "data size: " << data.size() << std::endl; std::cout << "address size: " << data["address"].size() << std::endl; std::cout << "friends size: " << data["friends"].size() << std::endl; return 0; }This code creates a JSON object with nested arrays and objects and prints the sizes of the top-level object, the `address` object, and the `friends` array. Package library used: `nlohmann/json`