JSON keys as symbols instead of strings in Ruby

Here’s a quickie that saved me from having to write a recursive symbolize_keys method.  I was dealing with stringified JSON in the params of one of my rails controllers.  I wanted to do the usual call to params[:foo], but when I did JSON.parse  on the string, the keys were strings instead of symbols, so I would need to do params[‘foo’] instead.  Luckily, as of Ruby 1.9, it’s possible to pass in symbolize_names: true as an option.

s = '{"hello": "kitty", "mickey": "mouse"}'
=> "{\"hello\": \"kitty\", \"mickey\": \"mouse\"}"

=> {"hello"=>"kitty", "mickey"=>"mouse"}

JSON.parse(s, symbolize_names: true)
=> {:hello=>"kitty", :mickey=>"mouse"}


A Productive Week

Yesterday, I completed my first week of employment at GoodReads.com.It’s tough starting a new job, learning a new programming language, and just getting used to new conventions, but it went alright.  I even got a few tickets done thanks to a lot of tips from my co-workers.

I mostly worked on google maps integration on our Events page (see here).  Now you can see a map of each individual event when you click through and get driving directions. Woohoo.

During my week at the SF office, we did some pair programming — it was my first time.  It’s stressful and frustrating but I think my pair partner and I finally got sorta in sync by the end. At least, more in sync than we started off.  One computer + two keyboards + two mouses will always be a little stressful, I think.  Despite that, I think pair programming is a good way to learn the ropes because there are tons of tips to pick up from seasoned co-workers.