Using Symbols
suggest changeYou can use JSON together with Ruby symbols. With the symbolize_names option, the keys in the resulting hash are symbols instead of strings.
require 'json'
json = '{ "a": 1, "b": 2 }'
puts JSON.parse(json, symbolize_names: true)
# >> {a: 1, b: 2}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents