Today was spent driving around the Bay Area taking in some of the sites and sounds. All the driving I did today means I got very little Ruby coding done today. I did however find some magic; I found the JSON library that is part of the Ruby Standard Library.

You might be asking so what? Well to me this is amazing, there are many third-party JSON serializers in the .NET world and there is the built-in JavaScriptSerializer. However, there is nothing that just works, nothing that makes it so simple that you could remember the complete syntax and never need to Google it.

In Ruby, there is just such a library a library that can do all the JSON work that you actually need to be done. Something that is powerful, yet simple. Ruby is very much geared toward developer productivity and happiness. The JSON library is a library that will make you feel good!

What is JSON? JavaScript Object Notation (JSON) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition.

So want to know how you can use the JSON library? As usual when it comes to Ruby quite easily. Here is some code taking a random Hash and converting it to JSON:

This bit of code results in:

{"userId":1,"title":"Yo my people","body":"Lorem Ipsum"}

To me I am blown away; all I need to do to get out a JSON object is create a Hash with some keys, call JSON.generate and go sip some cocktails? Really? Is there some trick? There must be magic going on here. Nope, just regular well thought-out Ruby that makes somebody’s life easier.

I like Ruby its a great language, it’s the small things like the JSON library that give it a massive edge over other programming languages and their ways.

Discussion, links, and tweets

My name is Deon Heyns and I am a developer learning things and documenting them in realtime. Python, Ruby, Scala, .NET, and Groovy are all languages I have written code in. I appeared in the New York Post once. I host my code up at GitHub and Bitbucket so have a look at my code, fork it and send those pull requests.