I'm using the code from Sorting an array of objects by property values to sort my Json. But it isn't working, I'm using request to store a Json from a web API and using jsonpath.
It isn't sorting, it's just sending me the GET content (before sort). I feel it's the problem with the parseFloat (line 15), but I am unsure how to fix it. I went into https://jsonpath.com/ to test a bit, and it should be ..rank
not .rank
My code:
var request = require('request');
var jp = require('jsonpath');
var options = {
'method': 'GET',
'url': 'https://groups.roblox.com/v1/groups/2642914/roles',
'headers': {
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
var obj = JSON.parse(response.body);
var rolesList = jp.query(obj, '$..roles');
rolesList.sort(function(a, b) {
return parseFloat(a.rank) - parseFloat(b.rank);
});
console.log(rolesList)
});