Converting JSONValue to AssociativeArray.

hype_editor onetestdsacc at yandex.ru
Tue Aug 2 08:56:55 UTC 2022


On Monday, 1 August 2022 at 22:47:03 UTC, Steven Schveighoffer 
wrote:
> On 8/1/22 2:00 PM, hype_editor wrote:
>> [...]
>
> ```d
> // option 1
>     string[string] aa_data;
>     foreach(string k, v; data) {
>         aa_data[k] = v.get!string;
>     }
> // option 2
>     import std.algorithm : map;
>     import std.array : assocArray;
>     import std.typecons : tuple;
>     auto aa_data = data.object
>         .byKeyValue
>         .map!(kv => tuple(kv.key, kv.value.get!string))
>         .assocArray;
> ```
>
> I personally prefer the straightforward loop.
>
> -Steve

Steve, thank you very much, works fine!


More information about the Digitalmars-d-learn mailing list