How to convert array of structs to JSON

mark mrmarkkoenig at gmail.com
Tue Jun 25 05:33:57 UTC 2019


I have the following array of structs:

struct Person {
     string name;
     int age;
};


Person people[];
Person p;

Person p1 = {
     "Bob",
     12
};

Person p2 = {
     "Bob",
     12
};

people ~= p1;
people ~= p2;

I've read through the std.json documentation, but I'm still 
confused as to how to create an array of objects, especially if 
the objects are structs.

I've included this:

JSONValue jj;
jj["nodes"].array = [];

But I get the error: JSONValue is not an object. Ideally, I'd 
like to have a json output that looks like this:

[

     {
         "name": "Bob",
         "age": 12
     },
     {
         "name": "Bob",
         "age": 12
     },
]

Any help would be greatly appreciated.



More information about the Digitalmars-d-learn mailing list