On 13.04.2015 um 01:48 Konstantin Ilchenko wrote:

(...)

but I don't get how to convert data to any useable type, Variant or associative array, or class instance.

I can do

auto data = json["data"]["other"].get!string;

But what to do, for example, with array of objects of 10 properties?

auto data = json["data"].to!array;

throws

Error: undefined identifier array, did you mean function asArray?
Serializing composite type VariantN!32LU which has no serializable fields

That should be json["data"].get!(Json[]) instead (to!(Json[]) works as well). Maybe adding support for json["data"].get!(Json.Type.object) would be an interesting alternative, though.

auto data = json["data"].to!object;

throws

Error: template instance to!(object) does not match template declaration to(T)()

Similarly, should be json["data"].get!(Json[string]).

class Handshake
{
     int some;
     string other;
}

auto data = json["data"].to!Handshake;

throws

Error: function vibe.data.json.Json.to!(Handshake).to has no return statement, but is expected to return a value of type inout(Handshake)
Error: template instance vibe.data.json.Json.to!(Handshake) error instantiating

This is done with deserializeJson: json["data"].deserializeJson!Handshake
You can process nested structures, arrays, AAs etc. with it. If performance is a concern, this also allows to process the JSON sting directly, without parsing it into a Json value first, so this is the generally recommended way to work with specific JSON structures.