Is there a simple way to convert these txt files into json formatted databases?

116 views
Skip to first unread message

Peter Joseph

unread,
Aug 19, 2015, 4:33:38 PM8/19/15
to beerdb
Is there a simple way to convert these txt files into json formatted databases?
And furthermore - what format is this?

####################################################
[boston]
Boston Beer Co. (Samuel Adams)|Boston Beer Company, 1984
city:boston
Boston | MA 02130 // 30 Germania St.

[clownshoes]
Clown Shoes
Ipswich | MA //
####################################################


Thanks!











Gerald Bauer

unread,
Aug 19, 2015, 4:43:02 PM8/19/15
to bee...@googlegroups.com
Hello,
   Thanks for your interest in beer.db.

  Your first question:


> Is there a simple way to convert these txt files into json formatted databases?

 It depends on your definition of simple e.g.  for example you import the datasets in your SQL database of choice e.g. SQLite, PostgreSQL, etc.

  Option 1) No coding required. Use your SQL db tool of choice to export to JSON, or [your data format here].

  Option 2) Write your own (little) script (in Ruby, Python, etc.) that exports to JSON or [your data format here]. - Bonus: Share your scripts with the world.

   You can see an example in ruby e.g. service.rb [1] at the beerkit repo. It's as simple as:

    get '/beer/:key' do |key|
      beer = Beer.find_by_key!( key )
      json beer.as_json_v2
   end

   Cheers.

[1] https://github.com/beerkit/beer.db.service.rack/blob/master/lib/beerdb/service.rb


Gerald Bauer

unread,
Aug 19, 2015, 4:48:30 PM8/19/15
to bee...@googlegroups.com
Hello,

   Your second question:


> And furthermore - what format is this?

   The format is "just" an extended version of the comma-separated values (CSV) format. The beerdb. parser/reader supports two versions:

  The classic (all fields in a single-line) version and a "modern" multi-line version. That's what this looks like:


[boston]
Boston Beer Co. (Samuel Adams)|Boston Beer Company, 1984
city:boston
Boston | MA 02130 // 30 Germania St.

   is basically the same as:

boston, Boston Beer Co. (Samuel Adams)|Boston Beer Company, 1984, city:boston, Boston | MA 02130 // 30 Germania St.

  This is just a comment line:
   ####################################################


  Cheers.

Reply all
Reply to author
Forward
0 new messages