Converting ActiveRecord instances to their JSON representation has always been a topic that has been dear to me. I'd tried to get a patch that adds
to_json to ActiveRecord into Rails (but the quality of my patch was lacking in a few respects). The Jsonifier plugin that I wrote tried to address the lack of built-in JSON serialization by adding a
ActiveRecord#to_json method that acts much like
So it is with mixed feelings when I discovered a couple of days ago when DHH committed a changeset that added a native
ActiveRecord#to_json method. Of course, I'm elated that JSON serialization is given first class attention now, since the raison d'être of Jsonifier and my Rails patch was to do just that. A little bit of me is selfishly disappointed since it means that Jsonifier has become quite obsolete!
But it is an excellent change, I look forward to patching it up (if DHH doesn't beat me to it - there've been so much activity on the Rails trunk recently) so that the JSON serializer supports an
:include options for including associations much like for
ActiveRecord#to_xml and Jsonifier's mixed in