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

Gerald Bauer <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAAxEZd-qATG1g0eiUBcDNLyQbDXAZn2VW4CwunCVTFyw48NApA@mail.gmail.com>
Hello,

  I've published a new library / gem, that is, csvjon 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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.