using vibe.d to parse json

Sönke Ludwig via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 7 15:15:14 PDT 2015


Am 26.03.2015 um 02:38 schrieb Laeeth Isharc:
> On Thursday, 26 March 2015 at 01:04:06 UTC, Jakob Ovrum wrote:
>> On Thursday, 26 March 2015 at 00:41:50 UTC, Laeeth Isharc wrote:
>>>> Yeah, it is not very intuitive. But it works.
>>>
>>> Thanks.
>>>
>>> Next question - how can I correctly deal with inconsiderately chosen
>>> JSON field names like 'private' (which conflict in a struct
>>> declaration with D language keywords).  A hack is to do a search and
>>> replace on the JSON before presenting it to vibe.d, but I wondered if
>>> there was a better way. Incidentally, vibe doesn't seem to like my
>>> replacing private with private_ - whereas privateX works.
>>>
>>>
>>> Laeeth.
>>
>> Use the @name attribute:
>>
>> http://vibed.org/api/vibe.data.serialization/name
>
> aha!  Thanks.  (and to dicebot - I am not sure index-based access works
> as the problem is in parsing stage, not accessing).

If I understood the issue correctly, there is also the possibility to 
append an underscore to the D field name in case of keyword conflicts:

struct S {
	int private_; // will be represented as "private"
}

This predated the @name attribute (and UDAs in general) and today the 
latter is probably more appropriate.


More information about the Digitalmars-d-learn mailing list