Insert Json into sqlite data base


#1

Hi,
I need to create table and insert below json response into sqlite data base.

{ “parameters”: [ { “name”: “Test”, “value”: “Testing”, “message”: “Success” } ], “statusCode”: 200 }

Have to create Database table as below and insert json response.
Parameters name,Value ,Message,statuscode

How to achieve this in Ruby on rails?

Thanks,
Raja


#2

it can be done without Rails with ruby

You will need this : https://github.com/sparklemotion/sqlite3-ruby

and the gems json depending of your version of ruby

require 'json'
value = '{"val":"test","val1":"test1","val2":"test2"}'
puts JSON.parse(value) # => {"val"=>"test","val1"=>"test1","val2"=>"test2"}


This article might help : https://hackhands.com/ruby-read-json-file-hash/

PS It's a huge security risk to accept input with these character:    # => {"}