json
json copied to clipboard
Allow ordered_json in NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE macro
Allow for ordered_json
type to be used with the define macros provided in macro_scope.hpp
.
Usage:
#include <cstdio>
#include <nlohmann/json.hpp>
struct mystruct
{
int x = 1;
double y = 2.0;
std::string z = "three";
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE
(
mystruct,
z,
y,
x
);
int main()
{
mystruct ms;
const auto msjson = nlohmann::to_string(nlohmann::ordered_json{{ "mystruct", ms }});
const std::string expected = R"({"mystruct":{"z":"three","y":2.0,"x":1}})";
printf("%s\n",msjson .c_str());
printf("%s\n",expected.c_str());
return 0;
}