i am using sequel and json gem in ruby
when i try to converting a record into json object and trying to get its fields my code is
require 'json'
require "rubygems"
require "sequel"
require 'yaml'
require "sequel/extensions/pg_array"
DB = Sequel.connect('postgres://ritesh:newpassword@localhost')
pokes=DB[:use];
car = {:make => pokes.all, :year => "2003"}
cp = pokes.filter(:id =>1).first.inspect
jj = cp.to_json
puts jj
parseObject = JSON.parse(cp)
in the last line i am getting error
"{:id=>1, :first_name=>\"Ritesh\", :last_name=>\"Mehandiratta\", :email=>\"riteshmehandiratta@gmail.com\", :zipcode=>\"127021\", :comapnay_name=>\"heroku\", :google_profile=>\"google\", :skype=>\"helloworld\", :phone=>\"9013895056\", :about=>\"i am a great person\", :linkedin_profile_url=>\"linkedin.com\", :comapny_url=>\"company.com\", :needs=>[\"Web Designer\", \"Web Developer\", \"SoftWare Developer\"], :offering=>[\"Web Designer\", \"Web Developer\", \"SoftWare Developer\"], :upcoming_meetings=>[1, 2, 3, 4], :past_meetings=>[1, 2, 3, 4], :top_matches=>[1, 2, 3, 4]}"
/home/ritesh/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/json/common.rb:148:in `parse': 743: unexpected token at '{:id=>1, :first_name=>"Ritesh", :last_name=>"Mehandiratta", :email=>"riteshmehandiratta@gmail.com", :zipcode=>"127021", :comapnay_name=>"heroku", :google_profile=>"google", :skype=>"helloworld", :phone=>"9013895056", :about=>"i am a great person", :linkedin_profile_url=>"linkedin.com", :comapny_url=>"company.com", :needs=>["Web Designer", "Web Developer", "SoftWare Developer"], :offering=>["Web Designer", "Web Developer", "SoftWare Developer"], :upcoming_meetings=>[1, 2, 3, 4], :past_meetings=>[1, 2, 3, 4], :top_matches=>[1, 2, 3, 4]}' (JSON::ParserError)
from /home/ritesh/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/json/common.rb:148:in `parse'
from hello1.rb:15:in `<main>'
when i parse jj variable like this as suggested in answer
jj = cp.to_json
puts jj
parseObject = JSON.parse(jj)
then i am getting error
"{:id=>1, :first_name=>\"Ritesh\", :last_name=>\"Mehandiratta\", :email=>\"riteshmehandiratta@gmail.com\", :zipcode=>\"127021\", :comapnay_name=>\"heroku\", :google_profile=>\"google\", :skype=>\"helloworld\", :phone=>\"9013895056\", :about=>\"i am a great person\", :linkedin_profile_url=>\"linkedin.com\", :comapny_url=>\"company.com\", :needs=>[\"Web Designer\", \"Web Developer\", \"SoftWare Developer\"], :offering=>[\"Web Designer\", \"Web Developer\", \"SoftWare Developer\"], :upcoming_meetings=>[1, 2, 3, 4], :past_meetings=>[1, 2, 3, 4], :top_matches=>[1, 2, 3, 4]}"
/home/ritesh/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/json/common.rb:148:in `parse': 743: unexpected token at '"{:id=>1, :first_name=>\"Ritesh\", :last_name=>\"Mehandiratta\", :email=>\"riteshmehandiratta@gmail.com\", :zipcode=>\"127021\", :comapnay_name=>\"heroku\", :google_profile=>\"google\", :skype=>\"helloworld\", :phone=>\"9013895056\", :about=>\"i am a great person\", :linkedin_profile_url=>\"linkedin.com\", :comapny_url=>\"company.com\", :needs=>[\"Web Designer\", \"Web Developer\", \"SoftWare Developer\"], :offering=>[\"Web Designer\", \"Web Developer\", \"SoftWare Developer\"], :upcoming_meetings=>[1, 2, 3, 4], :past_meetings=>[1, 2, 3, 4], :top_matches=>[1, 2, 3, 4]}"' (JSON::ParserError)
from /home/ritesh/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/json/common.rb:148:in `parse'
from hello1.rb:15:in `<main>'
instead of cp in jj only in string there is difference of
'{:id=>1
'"{:id=>1
note in two errors but error is same
why i am getting this parser exception error this is a valid json string.i have to convert this into a hash please tell a way how to convert into hash and how to rectify this error