On Tue, 21 Jan 2014 09:23:06 GMT, Sönke Ludwig wrote:

On Tue, 21 Jan 2014 08:59:28 GMT, Kai-Heng Feng wrote:

I came from C++ world,
I assumed that since Json is a struct, it should be default-initialized.
But in D world, struct is initialized by a factory function, am I right?

It is indeed default initialized (in contrast to C++, all values are default initialized in D unless = void; is used, not only struct types), but the default in this case was chosen to be Json.Type.undefined.

Another possibility to handle this transparently would be to let a member assignment such as j.id = ...; automatically set the type of j to object, but when initially writing this, I wanted to start with a rather strongly typed interface and evaluate more relaxed features later (because it's always easy to relax such restrictions, but not the other way around).

Thanks! Your answer explained my confusion.
Kudos for this great framework!