Am 29.07.2015 um 00:37 schrieb H. S. Teoh via Digitalmars-d:
On Tue, Jul 28, 2015 at 03:29:02PM -0700, Walter Bright via Digitalmars-d wrote:
[...]
3. Stepping back a bit, when I think of parsing JSON data, I think:

     auto ast = inputrange.toJSON();

where toJSON() accepts an input range and produces a container, the
ast. The ast is just a JSON value. Then, I can just query the ast to
see what kind of value it is (using overloading), and walk it as
necessary.

+1. The API should be as simple as possible.

http://s-ludwig.github.io/std_data_json/stdx/data/json/parser/toJSONValue.html


Ideally, I'd say hook it up to std.conv.to for maximum flexibility. Then
you can just use to() to convert between a JSON container and the value
that it represents (assuming the types are compatible).

We could maybe do that if we keep the current JSONValue as a struct wrapper around Algebraic. But it I guess that this will create an ambiguity between JSONValue("...") creating parsing a JSON string, or being constructed as a JSON string value. Or does to! hook up to something else than the constructor?


OTOH, some people might want the option of parser-driven data processing
instead (e.g. the JSON data is very large and we don't want to store the
whole thing in memory at once). I'm not sure what a good API for that
would be, though.

See http://s-ludwig.github.io/std_data_json/stdx/data/json/parser/parseJSONStream.html and the various UFCS "read" and "skip" functions in http://s-ludwig.github.io/std_data_json/stdx/data/json/parser.html

Reply via email to