json/tests/bazel/json_example_test.cpp
Fabian Meumertzheim cec4630c2d Setup for inclusion in the Bazel Central Registry
By adding a MODULE.bazel file, this library becomes usable with Bazel's
new external dependency management system Bzlmod.

The new tests are run when a new version is included in the Bazel
Central Registry and verify that the basic functionality works with the
provided Bazel setup.

See:
https://bazel.build/build/bzlmod
2022-11-01 09:34:59 +01:00

25 lines
633 B
C++

#include <iostream>
#include <string>
#include <nlohmann/json.hpp>
int main()
{
nlohmann::json j;
j["pi"] = 3.141;
j["happy"] = true;
j["name"] = "Niels";
j["nothing"] = nullptr;
j["answer"]["everything"] = 42;
j["list"] = {1, 0, 2};
j["object"] = {{"currency", "USD"}, {"value", 42.99}};
std::string s = j.dump();
if (s != R"({"answer":{"everything":42},"happy":true,"list":[1,0,2],"name":"Niels","nothing":null,"object":{"currency":"USD","value":42.99},"pi":3.141})")
{
std::cerr << "Unexpected JSON serialization: " << s << std::endl;
return 1;
}
return 0;
}