0

I am working in Ruby on Rails. I have a Json String like this

"{\"user\":{\"email\":\"blah@blah.com\",\"name\":\"blah Test 1051\",\"mobile\":\"9999999999\",\"dob\":\"00/00/0000\",\"street\":\"somewhere\",\"state\":\"something\",\"city\":\"nowhere\",\"pincode\":\"50000\",\"Event_Code\":\"e0031\"}}"

I need to convert this to JSON hash like this

{"user"=>{"email"=>"blah@blah.com", "name"=>"blah Test 1051", "mobile"=>"9999999999","dob"=>"00/00/0000","street"=>"somewhere","state"=>"something","city"=>"nowhere","pincode"=>"50000","Event_Code"=>"e0031"}}
Siva Praveen
  • 2,213
  • 17
  • 20

2 Answers2

2
require 'json'
h = JSON.parse string

This link will help to you..

https://hackhands.com/ruby-read-json-file-hash/

Dimuth Lochana
  • 239
  • 1
  • 3
  • 14
0
JSON.parse "{\"user\":{\"email\":\"blah@blah.com\",\"name\":\"blah Test 1051\",\"mobile\":\"9999999999\",\"dob\":\"00/00/0000\",\"street\":\"somewhere\",\"state\":\"something\",\"city\":\"nowhere\",\"pincode\":\"50000\",\"Event_Code\":\"e0031\"}}"

Check http://apidock.com/ruby/JSON/parse for more reference

Qaisar Nadeem
  • 2,404
  • 13
  • 23