23/05/10 03:43:26.68 fIRqc6o3.net
>>264
Ruby なら、
require 'json'
# 改行を削除する。削除しなくても同じ結果
input_json_str = <<'JSON'.delete( "\n" )
[{"ID": 1,"Level": 50, "Status": {"idx":1}},
{"ID": 1,"Level": 100, "Status": {"idx":2}},
{"ID": 2,"Level": 50, "Status": {"idx":3}},
{"ID": 3,"Level": 50, "Status": {"idx":4}},
{"ID": 3,"Level": 100, "Status": {"idx":5}}]
JSON
input_json_obj = JSON.parse( input_json_str )
# ID でグループ化して、最大Level のものを取得する
result = input_json_obj.group_by { |hash| hash[ "ID" ] }.map do |row|
row[ 1 ].max_by { |hash| hash[ "Level" ] }
end
p result
出力
[ {"ID"=>1, "Level"=>98, "Status"=>{"idx"=>2}},
{"ID"=>2, "Level"=>48, "Status"=>{"idx"=>3}},
{"ID"=>3, "Level"=>98, "Status"=>{"idx"=>5}} ]