# Pastebin KpMzpfCx require 'pp' # for inspection users = Array.new(3){|id| { "id"=>id, "username"=>"bobbyl1000", "scores"=>[ {"league" => "all", "group_id"=>nil, "percentile_score"=>"0.3669724771"}, {"league" => "ncb", "group_id"=>nil, "percentile_score"=>"0.3333333333"}, {"league" => "all", "group_id"=>1, "percentile_score"=>"1.0"}, {"league" => "ncb", "group_id"=>1, "percentile_score"=>"1.0"}, ], "avatar"=>{ "url"=>"https://s3.amazonaws.com/gamepredict/assets/logo-.png", "profile"=>{"url"=>"https://s3.amazonaws.com/gamepredict/assets/logo-profile.png"}, "small"=>{"url"=>"https://s3.amazonaws.com/gamepredict/assets/logo-small.png"} } } } result = users.map{|user| scores = user['scores'].select do |h| h['group_id'] == 1 && h['league'] == 'all' end pp scores user.merge('scores' => scores) } pp result