Home > Net >  How to convert json to old ruby hash object and migration
How to convert json to old ruby hash object and migration

Time:01-22

I have an api definition in json and I want to convert that to an old ruby hash representation like :

{:hello => 'there', ....}

Actually I want to use that with a create() statement really to add objects to db based on that definition.

I do want to use => because I am very used to it and frankly like it much more than the :

Is there also a tool that can convert that to a migration too? (I can alter the datatypes when needed).

I have quite a few of these APIs and it will take a lot of time to do that manually so I am wondering whether there's some sort of quick to use converter for such a case.

Thanks!

CodePudding user response:

You can simply use

Model.create(JSON.parse(json_string))
  •  Tags:  
  • Related