0
0
Rubyprogramming~5 mins

JSON library basics in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the JSON library in Ruby?
The JSON library in Ruby is used to convert Ruby objects into JSON strings and parse JSON strings back into Ruby objects.
Click to reveal answer
beginner
How do you convert a Ruby hash to a JSON string?
Use JSON.generate(your_hash) or your_hash.to_json to convert a Ruby hash into a JSON string.
Click to reveal answer
beginner
How do you parse a JSON string into a Ruby object?
Use JSON.parse(json_string) to convert a JSON string into a Ruby hash or array.
Click to reveal answer
beginner
What Ruby module must you require to use JSON methods?
You must include require 'json' at the top of your Ruby file to use JSON methods.
Click to reveal answer
intermediate
What is the difference between JSON.generate and JSON.dump?
JSON.generate returns a JSON string from a Ruby object. JSON.dump does the same but can also write the JSON string directly to an IO object like a file.
Click to reveal answer
Which method converts a Ruby hash to a JSON string?
AJSON.read
BJSON.parse
CJSON.generate
DJSON.load
What must you do before using JSON methods in Ruby?
Arequire 'json'
Binclude JSON
Cimport 'json'
Duse JSON.new
Which method parses a JSON string into a Ruby object?
AJSON.generate
BJSON.write
CJSON.dump
DJSON.parse
What does JSON.dump do that JSON.generate does not?
AWrites JSON directly to IO objects
BParses JSON strings
CConverts JSON to XML
DValidates JSON syntax
If you have a Ruby array, which method converts it to JSON?
AJSON.parse
BJSON.generate
CJSON.load
DJSON.read
Explain how to convert a Ruby hash to a JSON string and then back to a Ruby object.
Think about the methods to serialize and deserialize JSON.
You got /4 concepts.
    Describe the difference between JSON.generate and JSON.dump in Ruby.
    Consider where the JSON output goes.
    You got /3 concepts.