std.json API improvement - Request for code review

Brian Schott brian-schott at cox.net
Sun Sep 12 21:18:40 PDT 2010


I just found the phobos mailing list. Why is it on a completely
different server?

Regarding the bugs, my intent was just to improve the usefulness of the
existing implementation. I was not aware of any plans to drop this
module. (There's no notice to this effect in the documentation the way
there is with std.contracts)

What do you recommend for dealing with JSON files until this is sorted out?

On 09/12/2010 08:45 PM, Robert Jacques wrote:
> Hi Brain,
> This really belongs on the phobos mailing list as JSON isn't ready for
> public consumption yet (as far as I know). I would suspect that it even
> has a decent chance of being dropped in favor of serialization +
> variant. The implementation has several bugs. First, it doesn't parse
> Unicode escape sequences correctly (e.g. \u0026). Second, JSON has no
> integer type. Third, the serializer with certain JSON value inputs will
> write a JSON file that can not be read by the parser. It's also missing
> some key features, like output range and human readable output support.
> The design is very C-ish as opposed to D-ish: its composed of a bunch of
> free functions / types all containing JSON in their name. (i.e.
> parseJSON). These should all be encapsulated as member functions.
> 
> Getting more to the API itself, the reading of a JSON value is a use
> case that just isn't considered currently. Consider:
> 
> // It's relatively simple to write to a JSON value
> json["vector"]["x"] = 42.8;
> 
> // But reading it...
> real x;
> if(json["vector"]["x"].type == JSON_TYPE.INTEGER) {
>     x = json["vector"]["x"].integer;
> } else if(json["vector"]["x"].type == JSON_TYPE.FLOAT) {
>     x = json["vector"]["x"].floating;
> } else {
>     enforceEx!(JSONException)(false);
> }
> 
> By contrast, this is the API on my personal JSON library:
> json.vector.x = 42.8;
> auto x = json.vector.x.number;


More information about the Digitalmars-d mailing list