std.json API improvement - Request for code review

sybrandy sybrandy at gmail.com
Sun Sep 12 17:19:35 PDT 2010


On 09/12/2010 05:05 AM, Brian Schott wrote:
> Now that a few bugs are fixed in DMD (notably 4826), my improvements to
> std.json compile. My primary purpose in this code change is streamlining
> the process of creating JSON documents. You can now do stuff like this:
>
> auto json = JSONValue();
> json["numbers"] = [1, 3, 5, 7];
> json["nullValue"] = null;
> json["something"] = false;
> json["vector"] = ["x": 234.231, "y" : 12.8, "z" : 35.0];
> assert("vector" in json);
> json["vector"]["x"] = 42.8;
>
> More example usage:
> http://www.hackerpilot.org/src/phobos/jsontest.d
>
> The implementation of the actual JSON data structure and parsing /
> writing is unchanged. Ddoc comments were added so that the documentation
> page for the module won't be quite so empty.
>
> Implementation:
> http://www.hackerpilot.org/src/phobos/json.d
>
> I'd like to get this committed back to Phobos if there's a consensus
> that these changes make sense. Comments welcome. (Note: You'll need a
> DMD version built from SVN to use this)
>
> - Brian

Everything I've seen looks good to me, though I haven't tried to execute 
it.  The fact that I can directly manipulate a JSONValue looks good to 
me.  However, here's a question: if I have the following JSON document 
and parse it using parseJSON, will obj1 and obj2 both be JSONValues?  My 
current project deals with this type of situation on a regular basis, so 
I'm curious about how easy this will be to access the data.

Casey

{
     "obj1":
     {
         "obj2":
         {
             "val1": 1,
             "val2": "a string"
         },
         "val3": [ 1, 2, 3, 4]
     }
}


More information about the Digitalmars-d mailing list