// __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) // | | |__ | | | | | | version 3.12.0 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT import nlohmann.json; #include #include using namespace nlohmann::literals; // Exercise each name exported by the nlohmann.json module so that a missing or // broken export is caught at compile time. This target is only built (not run) // by the ci_module_cpp20 CI job, so the checks are primarily compile-time; the // return value additionally validates them if the binary is executed. int main() { // basic_json / json: parsing and value access nlohmann::json j = nlohmann::json::parse(R"({"a": 1, "list": [1, 2, 3]})"); const int a = j["a"].get(); // json_pointer and operator""_json_pointer nlohmann::json_pointer ptr = "/list/2"_json_pointer; const int last = j[ptr].get(); // operator""_json literal const nlohmann::json lit = R"([1, 2, 3])"_json; // ordered_json nlohmann::ordered_json oj; oj["b"] = 2; const int b = oj["b"].get(); // ordered_map alias nlohmann::ordered_map m; m["x"] = 1; // adl_serializer (reference the exported template) using serializer = nlohmann::adl_serializer; static_cast(sizeof(serializer)); // to_string const std::string dumped = nlohmann::to_string(j); // operator<< (hidden friend, reached via ADL through the module) std::ostringstream os; os << j << oj << lit; // use every result so the references cannot be optimized away return (a == 1 && last == 3 && b == 2 && lit.size() == 3 && m.size() == 1 && !dumped.empty() && !os.str().empty()) ? 0 : 1; }