# Serialized JSON object importation

**URL:** <https://www.ruby-forum.com/t/serialized-json-object-importation/191120>\
**Category:** Rails\
**Created:** [July 6, 2010, 12:05am UTC](https://www.ruby-forum.com/t/serialized-json-object-importation/191120 "2010-07-06T00:05:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![judge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@judge](https://www.ruby-forum.com/u/judge)\
**Post date:** [July 6, 2010, 12:05am UTC](https://www.ruby-forum.com/t/serialized-json-object-importation/191120/1 "2010-07-06T00:05:03Z")

</div>

Hi,

I would like to import a serialized object (from a JSON export) inside  
my database.

It work fine if for instance I do:

> > l = Yea.create(:title =\> “foo bar”)  
> > =\> #\<Yea id: 3, title: “foo bar”, created\_at: “2010-07-05 21:44:54”,  
> > updated\_at: “2010-07-05 21:44:54”\>
> 
> > j = l.to\_json  
> > =\> “{“yea”:{“created\_at”:“2010-07-05T21:44:54Z”,“title”:“foo  
> > bar”,“updated\_at”:“2010-07-05T21:44:54Z”,“id”:3}}”
> 
> > Yea.delete(3)  
> > =\> 1
> 
> > a = ActiveSupport::JSON.decode(j)  
> > =\> {“yea”=\>{“created\_at”=\>“2010-07-05T21:44:54Z”, “title”=\>“foo bar”,  
> > “updated\_at”=\>“2010-07-05T21:44:54Z”, “id”=\>3}}
> 
> > Yea.create(a.values)  
> > =\> [#\<Yea id: 4, title: “foo bar”, created\_at: “2010-07-05 21:44:54”,  
> > updated\_at: “2010-07-05 21:44:54”\>]

But I think this way is not good, because I would like to write this  
importation a little bit more generic, for Yea serialized instances or  
any other one. Is there a way to clean up this with ActiveRecord, for  
example?

Many thanks.
