jkcfg / jk

Configuration as Code with ECMAScript
https://jkcfg.github.io
Apache License 2.0
404 stars 30 forks source link

Support CSV files #340

Open alexec opened 4 years ago

alexec commented 4 years ago

Can we read CSV files please?

dlespiau commented 4 years ago

We do not provide specific support for CSV files at the moment, unfortunately. It's always possible to read a file as a string though, iterate over the lines and parse the fields in javascript.

I guess it could be somewhat possible to provide some built-in support, eg. transform a CSV file that looks like:

name,count
damien,2
michael,2

into something like

[{
    "name": "damien"
    "count": 2,
},{
    "name": "michael",
    "count": 2,
}]

but there's a lot of metadata to provide for this to work: column names, column types, field separator, ...

I'd lean towards writing that logic in js instead of providing built-in support /me thinks.

alexec commented 4 years ago

I think there are probably good NPM libraries for CSV parsing. We have data we need to build out app from, being able to use CSV would mean we could only use JK.

squaremo commented 4 years ago

CSV (tab-SV, etc.) can be more complicated than it seems, with quoting and so on. It may be worth building this in (go has encoding/csv), perhaps as an RPC if not a std.Format.