# ActiveResource with Json

**URL:** <https://www.ruby-forum.com/t/activeresource-with-json/158701>\
**Category:** Rails\
**Created:** [January 26, 2009, 11:50pm UTC](https://www.ruby-forum.com/t/activeresource-with-json/158701 "2009-01-26T23:50:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevedogers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9dc877/32.png) [@stevedogers](https://www.ruby-forum.com/u/stevedogers)\
**Post date:** [January 26, 2009, 11:50pm UTC](https://www.ruby-forum.com/t/activeresource-with-json/158701/1 "2009-01-26T23:50:00Z")

</div>

Hi all. I’m hoping maybe someone can help me out.

I recently switched from using xml to json in my ARe models. I was  
excited to see that in irb I was seeing dramatic improvements in  
speed. However, when I fired up the app in my browser I got an error  
on a local db find based upon an id i had intended to receive through an  
ARe record. I opened irb again to investigate:

object = AResource.find(461).id

the ARe record is found, however the id attribute returns as nil,  
where as, when I was using xml, I had no problems with it.

(the reaons i’m doing the find(id).id is to demonstrate that the  
record returned does not have the id which i used to search for the  
record. All other attributes are present, however, the object is also  
showing new\_record=true, which i’m supposing is the reason it has a  
nil id)

Any thoughts on what I can do maintain that id? The only thing I can  
come up with is that i have a local model name that is the same as the  
object class that is returned from the remote application, though, like  
I  
said, there was no problem when using xml.

The following is from irb (object1 is the xml request and object2 is  
the json request–both point to the same resource)

Code :

> > object1 = MMTest.find(1)  
> > =\> #\<MMTest:0x4058328 @prefix\_options={}, @attributes={“name”=\>“Visa”,  
> > “updated\_at”=\>nil, “id”=\>1, “status”=\>1}\>

> > object2 = MMCreditcardType.find(1)  
> > =\> #\<MMCreditcardType:0x404c4c4 @prefix\_options={}, @attributes=  
> > {“creditcard\_type”=\>#\<CreditcardType id: nil, name: “Visa”, status:  
> > true, created\_at: nil, updated\_at: nil\>}\>

Thanks in advance,

~Steve
