Last active
August 29, 2015 14:01
-
-
Save zackn9ne/6d6ab872708ae2863b77 to your computer and use it in GitHub Desktop.
Parse json files in Ruby
This file contains hidden or 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
http://www.ruby-doc.org/core-2.1.1/Enumerable.html#method-i-zip | |
add value to an array | |
users['Neel'][:favorite_numbers].push(64) or | |
users['Neel'][:favs] << 64 | |
add user to array | |
users['Jane'] = {:github => "janeplural", :nums => [58,48,44]} | |
.zip | |
.flatten | |
.uniq | |
loop through a json | |
num_array = [] | |
users.each do |k,v| | |
v[:favorite_numbers].each do |num| | |
num_array << num | |
end | |
end | |
uniq_array = num_array.uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment