std.json dynamic initialization of JSONValue

Robert Jacques sandford at jhu.edu
Tue Dec 6 19:48:34 PST 2011


On Tue, 06 Dec 2011 19:15:26 -0500, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Tuesday, December 06, 2011 18:26:39 Adam D. Ruppe wrote:
>> Kai Meyer Wrote:
>> > I like it. Any reason something like this doesn't already exist in
>> > std.json?
>> I think it's just that nobody has done updates to std.json for a while, but
>> I don't really know.
>
> I believe that Robert Jacques has a revised version of std.json that he
> intends to put up for review, but it relies on changes that he's made to
> std.variant which also need be reviewed.
>
> - Jonathan M Davis

Correct. Andrei suggested that since JSONValue is a tagged union, it should really use std.Variant.Algebraic as its representation, which necessitated fixing both Variant and Algebraic so that was possible. The code and documentation links are below if you'd like to try it out/comment on it. The only thing unintuitive in my revision from your use case is creating an empty JSON object or array:

JSON.Value myObject = JSON.Value[string].init;
JSON.Value myArray  = JSON.Value[].init;

Since this is undocumented :( I think I'm going to add some aliases (JSON.Object_init, JSON.Array_init) to simplify things for people.

https://jshare.johnshopkins.edu/rjacque2/public_html/json2.mht
https://jshare.johnshopkins.edu/rjacque2/public_html/variant.mht

https://jshare.johnshopkins.edu/rjacque2/public_html/json2.d
https://jshare.johnshopkins.edu/rjacque2/public_html/variant.d


More information about the Digitalmars-d mailing list