Code review: JSON unmarshaller

Tyler Jameson Little beatgammit at gmail.com
Mon Oct 15 12:03:29 PDT 2012


https://gist.github.com/3894337

This is my first non-trivial D code, and I'd eventually like to 
get this into Phobos as part of std.json.

I haven't written the marshaller yet, but that shouldn't be too 
hard. I wanted to get some feedback on whether this code is up to 
the quality standards of Phobos.

I used a lot of templates, so I hope I didn't break any cardinal 
sins, especially in terms of readability. I did my best in 
grokking std.traits, but I may have missed some subtleties about 
what the templates are actually testing.

I used asserts and contracts to validate input, so the following 
would throw an AssertError:

     int x = unmarshalJSON!int(`"5"`);

I wasn't sure if this is bad style, since AssertError is in 
core.exception. If this is considered bad style in D, I can 
create a JSONMarshalException and throw that instead.


More information about the Digitalmars-d-learn mailing list