Complete the code to load the JSON library.
require '[1]'
The JSON library in Ruby is loaded using require 'json'.
Complete the code to parse a JSON string into a Ruby hash.
data = JSON.[1]('{"name":"Alice","age":30}')
JSON.generate which converts Ruby objects to JSON string.JSON.dump which also converts Ruby objects to JSON string.Use JSON.parse to convert a JSON string into a Ruby hash.
Fix the error in the code to convert a Ruby hash to a JSON string.
json_string = JSON.[1]({name: "Bob", age: 25})
JSON.parse which is for reading JSON strings, not creating them.JSON.load which is for loading JSON from files or strings.Use JSON.generate to convert Ruby objects into JSON strings.
Fill both blanks to create a JSON string from a Ruby hash and then parse it back.
json_str = JSON.[1]({city: "Paris", country: "France"}) data = JSON.[2](json_str)
JSON.dump instead of generate for the first step.JSON.load instead of parse for the second step.First, use JSON.generate to create a JSON string from a Ruby hash. Then, use JSON.parse to convert the JSON string back into a Ruby hash.
Fill all three blanks to parse a JSON string, access a value, and generate a new JSON string.
data = JSON.[1]('{"fruit":"apple","count":10}') count = data[[2]] new_json = JSON.[3]({fruit: "apple", count: count + 5})
JSON.load instead of parse.JSON.dump instead of generate.Use JSON.parse to read the JSON string. Access the value with the key "count". Then use JSON.generate to create a new JSON string with the updated count.