Convert "complex" JSON data to a hash

I am using Ruby on Rails 3 and I am trying to convert the following JSON data.

"{\"errors\":{\"base\":\"Invalid field.\"}}"

to a hash accessible this way:

@internal_test1[:errors][:base]
# => "Invalid field"

How to do it?


UPDATE

@internal_test1 = "{\"errors\":{\"base\":\"Invalid email/password combination.\"}}"
test = ActiveSupport::JSON.decode(@internal_test1)
@internal_test2 = test["errors"]

Debugging

@internal_test1
--- "{\"errors\":{\"base\":\"Invalid email/password combination.\"}}"

@internal_test2
--- 
base: Invalid email/password combination.
+3
source share
1 answer
> @internal_test1 = ActiveSupport::JSON.decode "{\"errors\":{\"base\":\"Invalid field.\"}}"
 => {"errors"=>{"base"=>"Invalid field."}} 
> @internal_test1["errors"]
 => {"base"=>"Invalid field."} 
+9
source

Source: https://habr.com/ru/post/1796560/


All Articles