I am trying to call the uniq method on the follow json so that it would only return unique result base on employee_id
# Json array
a ={
results: [
{
employee: {
name: "A",
employee_id: "A-00016",
title: 1
}
},{
employee: {
name: "A",
employee_id: "A-00016",
title: 2
}
},{
employee: {
name: "C",
employee_id: "C-00017",
title: 3
}
}
]
}
# Calling uniq on a
a.uniq { |p| p.values_at(:employee_id) }
However, I am only getting this result
{
results: [
{
employee: {
name: "A",
employee_id: "A-00016",
title: 1
}
}
]
}
Instead of what I want
{
results: [
{
employee: {
name: "A",
employee_id: "A-00016",
title: 1
},{
employee: {
name: "C",
employee_id: "C-00017",
title: 3
}
}
]
}
Am I using the correct method to output the result I want?
a[:results].uniq!but you have title=1 in the first instance and title=2 in the second. So, ruby will consider the two first as different.