std.data.json formal review

Sönke Ludwig via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 28 11:45:49 PDT 2015


Am 28.07.2015 um 17:19 schrieb Etienne Cimon:
> On Tuesday, 28 July 2015 at 14:07:19 UTC, Atila Neves wrote:
>> Start of the two week process, folks.
>>
>> Code: https://github.com/s-ludwig/std_data_json
>> Docs: http://s-ludwig.github.io/std_data_json/
>>
>> Atila
>
> This is cool:
> https://github.com/s-ludwig/std_data_json/blob/aac6d846d596750623fd5c546343f4f9d19447fa/source/stdx/data/json/value.d#L183
>
>
> I was getting tired of programmatically checking for null, then checking
> for object type, before moving along in the object and doing the same
> recursively. Not quite as intuitive as the optional chaining ?. operator
> in swift but it gets pretty close
> https://blog.sabintsev.com/optionals-in-swift-c94fd231e7a4#5622

An idea might be to support something like this:

json_value.opt.foo.bar[2].baz
or
opt(json_value).foo.bar[2].baz

opt (name is debatable) would return a wrapper struct around the 
JSONValue that supports opDispatch/opIndex and propagates a missing 
field to the top gracefully. It could also keep track of the complete 
path to give a nice error message when a non-existent value is dereferenced.


More information about the Digitalmars-d mailing list