I'm trying to find a way to sort JSON data in ruby. It's stored as a fairly complicated (I think so anyway) hash that looks like this:
{
"allergies": {
"allergy": [
{
"id": "11426793",
"name": "Milk",
"category": "Food Allergy",
"createdPerson": "AGUDELO-HERNANDEZ ARCADIO",
"onsetDate": "2014-05-05T00:29:28-04:00"
}, {
"id": "11426788",
"name": "Antibiotics",
"category": "Drug Allergy",
"createdPerson": "Smith John H",
"onsetDate": "2014-05-04T22:29:28-04:00"
}
]
},
"responseErrors": {
"responseError": []
}
}
There's a lot more "Allergy" objects that exist in the actual data, and I want to be able to sort them by the "onsetDate" then by "name". I've tried:
sorted = @allergies["allergies"].sort_by { |hsh| hsh["name"] }
but I get the following error:
no implicit conversion of String into Integer (TypeError)