I’m trying to serialize and deserialize a hash. When the hash is deserailized, the keys are de-symbolized; e.g. not more :one, rather “one”.
From rails console:
>>h = { :one =>1, :two => "two"}
{:one=>1, :two=>"two"}
>>j = ActiveSupport::JSON.encode(h)
"{\"one\":1,\"two\":\"two\"}"
>>h2 = ActiveSupport::JSON.decode(j)
{"one"=>1, "two"=>"two"}
>>h2[:one]
nil
>>h[:one]
1
I’ve switched to using Marshal.dump/load for now. However, I wanted to throw this out there to see if there was a way to keep this in JSON (just for readability).
1 Answer