脳汁portal

アメリカ在住(だった)新米エンジニアがその日学んだIT知識を書き綴るブログ

sinatraでhashデータをJSONとして返す方法

方法

require 'json'
return #{hash}.to_json

require 'sinatra'
require 'json'

get '/top' do
  hash = {
    "key1" => 1,
    "key2" => 2,
    "key3" => 3,    
  }

  return hash.to_json
end