csvjson library / gem v1.0 - read tabular data in the CSV <3 JSON format, that is, comma-separated values CSV (line-by-line) records with JSON encoding rules

8 views
Skip to first unread message

Gerald Bauer

unread,
Oct 15, 2018, 9:22:09 AM10/15/18
to www...@googlegroups.com
Hello,

I've published a new library / gem, that is, csvjson that lets you
read tabular data in the (new) CSV <3 JSON format, that is,
comma-separated values CSV (line-by-line) records with javascript
object notation (JSON) encoding rules.

What's CSV <3 JSON?

CSV <3 JSON is a Comma-Separated Values (CSV)
variant / format / dialect
where the line-by-line records follow the
JavaScript Object Notation (JSON) encoding rules.
It's a modern (simple) tabular data format that
includes arrays, numbers, booleans, nulls, nested structures, comments and more.
Example:

# "Vanilla" CSV <3 JSON

1,"John","12 Totem Rd. Aspen",true
2,"Bob",null,false
3,"Sue","Bigsby, 345 Carnival, WA 23009",false

or


# CSV <3 JSON with array values

1,"directions",["north","south","east","west"]
2,"colors",["red","green","blue"]
3,"drinks",["soda","water","tea","coffe"]
4,"spells",[]


And how to read / parse in ruby? Example:

txt <<=TXT
# "Vanilla" CSV <3 JSON

1,"John","12 Totem Rd. Aspen",true
2,"Bob",null,false
3,"Sue","Bigsby, 345 Carnival, WA 23009",false
TXT

records = CsvJson.parse( txt ) ## or CSV_JSON.parse or CSVJSON.parse
pp records
# => [[1,"John","12 Totem Rd. Aspen",true],
# [2,"Bob",nil,false],
# [3,"Sue","Bigsby, 345 Carnival, WA 23009",false]]

# -or-

records = CsvJson.read( "values.json.csv" ) ## or CSV_JSON.read or
CSVJSON.read
pp records
# => [[1,"John","12 Totem Rd. Aspen",true],
# [2,"Bob",nil,false],
# [3,"Sue","Bigsby, 345 Carnival, WA 23009",false]]

# -or-

CsvJson.foreach( "values.json.csv" ) do |rec| ## or
CSV_JSON.foreach or CSVJSON.foreach
pp rec
end
# => [1,"John","12 Totem Rd. Aspen",true]
# => [2,"Bob",nil,false]
# => [3,"Sue","Bigsby, 345 Carnival, WA 23009",false]

and so on.

Happy data wrangling with ruby (and csv and json). Cheers. Prost.

[1] https://github.com/csv11/csvjson - the csvjson library (reader / parser)
[2] https://github.com/csv11/csv-json - the CSV <3 JSON format
Reply all
Reply to author
Forward
0 new messages