D JSON (WAT?!)

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 24 09:54:51 PDT 2014


On Thu, 24 Jul 2014 16:14:15 +0000, Pavel wrote:

> On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote:
>> On Thu, 24 Jul 2014 16:04:01 +0000, Pavel wrote:
>>> 
>>> Thanks to all you folks who explained "in" operator for me. My bad.
>>> Let's focus on the real problem, which is JSON wrapper class. Is it
>>> needed? Wouldn't it be better to get AA from parseJSON?
>>
>> The following are valid JSON:
>>
>> auto json1 = parseJSON(`1`);
>> auto json2 = parseJSON(`"foo"`);
>> auto json3 = parseJSON(`[1, 2, 3]`);
>>
>> None of these fit naturally into an JSONValue[string] return type.
> 
> Oh, man! You're wrong!!! Read: http://www.json.org/, and try putting "1"
> or "foo" as JSON string here: http://jsonlint.com/

Nope, while the spec calls out objects and arrays as the structural 
elements of JSON, it never requires (anywhere that I can find) that a 
complete JSON document have one of these at the root.  A valid JSON value 
is defined as

"A JSON value can be an object, array, number, string, true, false, or 
null"[1]

Thus the parseJSON function is defined as parsing as JSONValue.

1 http://www.ecma-international.org/publications/files/ECMA-ST/
ECMA-404.pdf, p2


More information about the Digitalmars-d-learn mailing list