Skip to content

Instantly share code, notes, and snippets.

@zackn9ne
Last active August 29, 2015 14:01
Show Gist options
  • Save zackn9ne/6d6ab872708ae2863b77 to your computer and use it in GitHub Desktop.
Save zackn9ne/6d6ab872708ae2863b77 to your computer and use it in GitHub Desktop.
Parse json files in Ruby
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