[phobos] Plans for std.json

Brian Schott briancschott at gmail.com
Thu Oct 28 00:14:05 PDT 2010


The DMD 2.050 beta zip contains no mention of std.json being scheduled
for eventual replacement. Is it really a good idea to have another
release with this code included and no warning that it will eventually
go away?

On 10/23/2010 09:30 PM, Andrei Alexandrescu wrote:
> I strongly believe std.json must be replaced. Here is my list of
> grievances and requirements:
>
> * JSONValue is utterly unsafe because it relies on an open tagged
> union. Essentially memory safety is entirely dependent on the user.
>
> * Even if the union were made safe, handling things with an enum is
> antiquated. The code should use types throughout, a la Algebraic, or -
> better yet - use Algebraic itself:
>
> struct JSONFalse {};
> struct JSONTrue {};
> struct JSONNull {};
>
> alias Algebraic!(
>     string,
>     long,
>     This[string],
>     This[],
>     JSONTrue,
>     JSONFalse,
>     JSONNull
> ) JSONValue;
>
> * The function parseJSON takes a range but not by reference, which
> means there is no way for the caller to know the new range position
> after having parsed one json object.
>
> * toJSON returns a string, which is inefficient for large objects. It
> should take an output range.
>
> Even if we later add serialization based on json transport, a simple,
> independent API would be beneficial for many. I'm thinking in fact of
> adding support for Json in std.format by means of %j. So then you can
> read and write Json stuff with writef and readf.
>
>
> Andrei



More information about the phobos mailing list