Wanted: Review manager for std.data.json

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 16 05:49:16 PDT 2015


On 2015-04-16 14:17, Sönke Ludwig wrote:

> The simplest target for a serialization library would be to generate a
> stream of JSONParserNodes. That way the serializer doesn't have to keep
> track of nesting levels and can reuse the pretty printing functionality
> of stdx.data.generator.
>
> However, this currently requires an input range of JSONParserNodes,
> which looks like it is suboptimal for a serializer (either requires an
> explicitly allocated node array, or a strange serializer architecture
> that directly works as an input range).

The serialization library I'm working on has an output range interface.

> For that reason I'm thinking about providing an output range interface like so:
>
>      auto dst = appender!string;
>      auto rng = jsonOutputRange(dst);
>
>      JSONParserNode n;
>      // start an object
>      n.kind = JSONParserNode.Kind.objectStart;
>      rng.put(n);
>
>      // write a single entry "foo": 10.5
>      n.key = "foo";
>      rng.put(n);
>      rng.put(10.5);
>
>      // write another entry "bar": true
>      n.key = "bar";
>      rng.put(n);
>      rng.put(true);
>
>      // finish the object
>      n.kind = JSONParserNode.Kind.objectEnd;
>      rng.put(n);
>
>      writefln("JSON: %s", dst.data);
>
> What do you think?

That looks very handy, that would be great to have.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list