Last active
August 29, 2015 14:18
-
-
Save EmmaB/0393d6b99e068278e81e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the Ruby JSON gem to parse data in the JSON format | |
json = JSON.parse(our_names) | |
# Get the first person's firstname. Ruby counts from 0, not 1! | |
json[0]["firstname"] | |
=> "Emma" | |
# Get the second person's firstname | |
json[1]["firstname"] | |
=> "David" | |
# Get each bit of the JSON data... | |
json.each do |person| | |
# ... and print the firstname and last name, with a space in the middle. | |
puts person["firstname"] + " " + person["lastname"] | |
end | |
=> "Emma Barnes", "David Aldridge", "Rob Jones" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment