# Convert XML/JSON reponse to ActiveRecord object

**URL:** <https://www.ruby-forum.com/t/convert-xml-json-reponse-to-activerecord-object/180315>\
**Category:** Rails\
**Created:** [December 17, 2009, 8:38am UTC](https://www.ruby-forum.com/t/convert-xml-json-reponse-to-activerecord-object/180315 "2009-12-17T08:38:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [December 17, 2009, 8:38am UTC](https://www.ruby-forum.com/t/convert-xml-json-reponse-to-activerecord-object/180315/1 "2009-12-17T08:38:30Z")

</div>

I need to convert the xml/JSON response into an ActiveRecord object.

For example,

\<?xml version="1.0" encoding="UTF-8"?\> true removed\_email\_address@domain.invalid 1 9324405627 9324405627 Haria 1 2009-12-07T07:01:20+05:30 

i got the server response as the format of the above XMl/JSON. i wish to  
convert this xml to ActiveRecord object as like below

[#\<Salesman id: 1, updated\_at: “2009-12-07 07:01:20”, name: “Haria”,  
mobile: “9324405627”, email: “removed\_email\_address@domain.invalid”, stockist\_id: 1, active:  
true, mdn\_number: 9324405627, password: nil\>]

I need the above conversion for fetching records easily in the ‘for’  
loop  
like:

for salesman in salesmen  
Name: \<%=salesman.name%\>  
Email: \<%=salesman.email%\>  
end

Please give me a solution as soon as possible?

Thanks

---

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [December 18, 2009, 7:53am UTC](https://www.ruby-forum.com/t/convert-xml-json-reponse-to-activerecord-object/180315/2 "2009-12-18T07:53:41Z")

</div>

Manivannan J. wrote:

> I need to convert the xml/JSON response into an ActiveRecord object.

ActiveResource should be what you’re looking for:

[http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=C00000606&name=ActiveResource](http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=C00000606&name=ActiveResource)
