std.jgrandson

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 5 06:24:17 PDT 2014


On Tuesday, 5 August 2014 at 12:40:25 UTC, Daniel Murphy wrote:
> "Jacob Carlborg"  wrote in message 
> news:kvuaxyxjwmpqrorlozrz at forum.dlang.org...
>
>> > This is exactly what I need in most projects.  Basic types, 
>> > arrays, AAs, and structs are usually enough.
>>
>> I was more thinking only types that cannot be broken down in 
>> to smaller pieces, i.e. integer, floating point, bool and 
>> string. The serializer would break down the other types in to 
>> smaller pieces.
>
> I guess I meant types that have an obvious mapping to json 
> types.
>
> int/long -> json integer
> bool -> json bool
> string -> json string
> float/real -> json float (close enough)
> T[] -> json array
> T[string] -> json object
> struct -> json object
>
> This is usually enough for config and data files.  Being able 
> to do this is just awesome:
>
> struct AppConfig
> {
>    string somePath;
>    bool someOption;
>    string[] someList;
>    string[string] someMap;
> }
>
> void main()
> {
>    auto config = 
> "config.json".readText().parseJSON().fromJson!AppConfig();
> }
>
> Being able to serialize whole graphs into json is something I 
> need much less often.

If I'm right, json has just one numeric type. No difference 
between integers / float and no limits.

So probably the mapping is:

float/double/real/int/long => number





More information about the Digitalmars-d mailing list