mirror of
https://github.com/nlohmann/json
synced 2024-11-22 12:00:05 +00:00
7b6cf5918b
Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
33 lines
513 B
C++
33 lines
513 B
C++
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace ns
|
|
{
|
|
// a simple struct to model a person
|
|
struct person
|
|
{
|
|
std::string name;
|
|
std::string address;
|
|
int age;
|
|
};
|
|
} // namespace ns
|
|
|
|
namespace ns
|
|
{
|
|
void to_json(json& j, const person& p)
|
|
{
|
|
j = json{ {"name", p.name}, {"address", p.address}, {"age", p.age} };
|
|
}
|
|
} // namespace ns
|
|
|
|
int main()
|
|
{
|
|
ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60};
|
|
|
|
json j = p;
|
|
|
|
std::cout << j << std::endl;
|
|
}
|