I have a json object coming from an external JSON file (I cannot change this):
{
"lcContact": {
"Alternate1": {
"last_name": "Williams",
"first_name": "Robert",
"rank": 5
},
"Alternate2": {
"last_name": "Crowley",
"first_name": "Joseph",
"rank": 9
},
"Primary": {
"last_name": "Garbolino",
"first_name": "Robert",
"rank": 2
}
}
}
Then, I am using jQuery to read this:
$.getJSON('file.json', function(json) {
object = json;
var this_parent = Object.keys(json)[0];
$.each(json[this_parent], function(this_parent) {
html += '<tr><td class="rank">' + this.rank + '</td><td>' + this.first_name + ' ' + this.last_name +'</td><td class="rank">' + this.rank + '</td></tr>';
});
$('table tbody.active').html(html);
});
My problem is that the ranks are coming through in random order (5,9,2). I need to output the JSON data in order by rank.
Can someone please help me to output the data IN ORDER based on the person's rank?
Please let me know if you need more information. Thanks in advance!