Combining JSON arrays into a single JSON array -- better way than this?
Salih Dincer
salihdb at hotmail.com
Mon Aug 1 17:02:10 UTC 2022
On Monday, 1 August 2022 at 08:48:28 UTC, ikelaiah wrote:
> On Monday, 1 August 2022 at 07:35:34 UTC, Christian Köstlin
> wrote:
>
>> An arguably shorter solution (that drops some of your logging)
>> could be:
>>
>> ```d
>> import std;
>>
>> void main() {
>> dirEntries(".", "*.json", SpanMode.shallow)
>> .filter!(f => !f.name.canFind("output"))
>> .map!(readText)
>> .map!(parseJSON)
>> .fold!((result, json) { result ~= json.array; return
>> result; })
>> .toPrettyString
>> .reverseArgs!(std.file.write)("output-combined.json");
>> }
>> ```
>> not sure if you are looking for this style though.
>>
>>
>> kind regards,
>> Christian
>>
>
> Hi Christian,
>
> So we can do that in D?!
> Thanks for sharing this amazing approach.
>
> -ikelaiah
When printing the steps import std.stdio : writeln; use it. Thus,
it does not confilics with std.file.
SDB at 79
More information about the Digitalmars-d-learn
mailing list