Combining JSON arrays into a single JSON array -- better way than this?

kdevel kdevel at vogtner.de
Mon Aug 1 18:13:12 UTC 2022


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");
> }
> ```

Is there an implementation which does not interpret the objects 
in the array:

Case 1
```
[{"A":"A","A":"B"}] -> [
     {
         "A": "B"
     }
]
```

Case 2
```
[1.0000000000000001] -> [
     1.0
]
```

Case 3
```
[99999999999999999999] -> 
std.conv.ConvOverflowException at ...Overflow in integral conversion
```





More information about the Digitalmars-d-learn mailing list