How to: Return JSON from Sinatra

It's so easy to output JSON from Sinatra it will take longer to read this post than to actually do it

First, make sure you have the 'json' gem:

sudo gem install json

Now all you have to do is spit out some JSON using the to_json method provided by the gem. Here is a simple example to try it out:

It's that simple