Forum: Ruby on Rails converting ActiveRecord objects to json

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A3953d877ffa7827eb7a7e9b0d41a674?d=identicon&s=25 Ryan Hanks (Guest)
on 2007-07-26 07:29
(Received via mailing list)
I have an ActiveRecord model with a boolean attribute.  If I call
to_json on an instance of this model, a get something like the

"{attributes : { my_boolean : \"0\" } }"
"{attributes : { my_boolean : \"1\" } }"

why is my boolean attribute being converted to a string?

if i call my_model_obj.attributes.to_json i get: "{ my_boolean :
false }" or "{ my_boolean : true }", which are both valid JSON
representation according to the grammar specified at,
and definitely the preferred representation when testing for truth in

json_str = "{attributes : { my_boolean : \"0\" } }"
obj = eval(json_str)
if(obj.attributes.my_boolean) {
  // shouldn't execute this bc my_boolean is false

can anyone tell me why this is?  or what i might be doing wrong?
This topic is locked and can not be replied to.