jsonQ icon indicating copy to clipboard operation
jsonQ copied to clipboard

Sort Entire Array rather than just the found parameter

Open Cleanshooter opened this issue 8 years ago • 2 comments

Rather than having the sort method return only the value of the provided key it would be more useful if there were an option to return the entire JSON object with all data still intact sorted based on the key/parameter identified. Returning an array of sorted values isn't that helpful when it comes to a sort command for most query languages.

Cleanshooter avatar Dec 06 '16 17:12 Cleanshooter

Actually, sortMethod do inplace sorting so you can do just

var family = jsonQ(jsonObj);
family.sort('name');

So here now family jsonQ is a sorted object.

Right now .sort method returns a jsonQ object which is simialiar to (family.find('name')), but sorted. So if you do

var family = jsonQ(jsonObj);
var names = family.sort('name');

you will get the names

But yes, I agree it should return the family jsonQ object instead of names. Will check for the impact and will make this change.

s-yadav avatar Dec 06 '16 18:12 s-yadav

Is this available now?

jomy-joseph avatar Mar 20 '18 06:03 jomy-joseph