Skip to content

Instantly share code, notes, and snippets.

@EmmaB
Last active August 29, 2015 14:18
Show Gist options
  • Save EmmaB/0393d6b99e068278e81e to your computer and use it in GitHub Desktop.
Save EmmaB/0393d6b99e068278e81e to your computer and use it in GitHub Desktop.
# 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