Vibe.d json to csv

Sebastiaan Koppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 4 21:24:25 PDT 2015


So I am using vibe.d json module to parse some array data with 
homogeneous objects, and I want to convert it to CSV.

Aside from encoding double-qoutes, this is want I came up with to 
generate the header:

```
void csvHeader(const Json jsonObject)
{
	return keys(jsonObject.get!(Json[string])).stdMap!(a 
=>`"`~a~`"`).joiner(",");
}
```

I can probably use zip to get the quotes around the names, to 
avoid concatenation. But it works fine the way it is. The problem 
is, the following doesn't:

```
void csvRow(const Json jsonObject)
{
	return values(jsonObject.get!(Json[string])).stdMap!(a 
=>`"`~a~`"`).joiner(",");
}
```

source\app.d(84): Error: template std.algorithm.joiner cannot 
deduce function from argument types !()(MapResult!(__lambda3, 
const(Json)[]), string), candidates are:
std\algorithm.d(3403): std.algorithm.joiner(RoR, Separator)(RoR 
r, Separator sep) if (isInputRange!RoR && 
isInputRange!(ElementType!RoR) && isForwardRange!Separator && 
is(ElementType!Separator : ElementType!(ElementType!RoR)))
std\algorithm.d(3670): std.algorithm.joiner(RoR)(RoR r) if 
(isInputRange!RoR && isInputRange!(ElementType!RoR))


More information about the Digitalmars-d-learn mailing list