ActiveRecord serialize using JSON instead of YAML

Toby Hede picture Toby Hede · Jan 17, 2010 · Viewed 45.1k times · Source

I have a model that uses a serialized column:

class Form < ActiveRecord::Base
  serialize :options, Hash
end

Is there a way to make this serialization use JSON instead of YAML?

Answer

Justas L. picture Justas L. · Aug 7, 2011

In Rails 3.1 you can just

class Form < ActiveRecord::Base
  serialize :column, JSON
end

Hope that helps