Casting JSONValues arrays to native arrays ... ??? ...

james.p.leblanc james.p.leblanc at gmail.com
Fri Sep 24 04:58:02 UTC 2021


On Thursday, 23 September 2021 at 20:32:36 UTC, james.p.leblanc 
wrote:
> On Thursday, 23 September 2021 at 19:18:11 UTC, james.p.leblanc 
> wrote:
>> On Thursday, 23 September 2021 at 19:04:47 UTC, Steven 
>> Schveighoffer wrote:
>>> On 9/23/21 2:20 PM, james.p.leblanc wrote:
>
> ```
> Produces:
>
> typeid(jj): std.json.JSONValue, jj: 
> {"ba":[true,false,true],"d":[1.23399999999999999]}
> typeid(z5): question.main.MapResult!(__lambda2, 
> JSONValue[]).MapResult, z5: [true, false, true]
> z5: [true, false, true]
>

Sigh ... my suggested "minor edit" above produces a "map result" 
instead of
the desired native array ... here is the **fix** by appending 
".array" at the
end (which is the suffix Steve originally offered).  The 
following gives
the desired **bool[]** result.

```d
import std.array;

    auto z5 = jj["ba"].array.map!(v => v.get!bool).array;
    writeln("typeid(z5): ", typeid(z5), ", z5: ", z5);
    writeln("z5: ", z5);
```

Regards,
James





More information about the Digitalmars-d-learn mailing list