Ruby json/messagepack
Ruby193 json/messagepackメモ
一度シリアライズするとkeyがStringになる
- json
require 'json' def hashtojson {"hoge" => 1, :fuga => 2}.to_json end def jsontohash(arg) JSON.parse(arg) end puts jsontohash(hashtojson) #=> {"hoge" => 1, "fuga" => 2}
- messagepack
require 'msgpack' def hashtomsgpack {"hoge" => 1, :fuga => 2}.to_msgpack end def msgpacktohash(arg) MessagePack.unpack(arg) end puts msgpacktohash(hashtomsgpack) #=> {"hoge" => 1, "fuga" => 2}