# Converting ActiveRecord objects to json

**URL:** <https://www.ruby-forum.com/t/converting-activerecord-objects-to-json/110423>\
**Category:** Rails\
**Created:** [July 26, 2007, 7:29am UTC](https://www.ruby-forum.com/t/converting-activerecord-objects-to-json/110423 "2007-07-26T07:29:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [July 26, 2007, 7:29am UTC](https://www.ruby-forum.com/t/converting-activerecord-objects-to-json/110423/1 "2007-07-26T07:29:55Z")

</div>

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  
following:

“{attributes : { my\_boolean : "0" } }”  
or  
“{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  
[http://www.json.org](http://www.json.org),  
and definitely the preferred representation when testing for truth in  
javascript

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?
