I read the data on the Internet, but it is in a string format. How can I make it return a JSON object.
Sample data:
text = '{"one":1,"two":2}'
Conversion Example:
data = JSON.parse(text).to_json
But when I do this:
puts data.class #=> String
Omit to_json : it converts the hash back to json! (JSON → Hash → JSON)
to_json
require 'json' text = '{"one":1,"two":2}' data = JSON.parse(text) # <--- no `to_json` # => {"one"=>1, "two"=>2} data.class # => Hash