JQuery: Sorting JSON results

JQuery. Write less, do more

This is a follow up to a previous post on sorting elements using JQuery. A few people messaged me asking how to modify the code to sort JSON results from a ajax request so here it goes.

The JSON (json.php):

We’re going to sort these results by the ‘name’ field and apply them to a ul list. First save the above JSON to your server and call it json.php.

The HTML/JS:

That’s it! After you save the above html to your server, you should see a case-insensitive sorted list of names from your JSON file in your list. If you want to sort using another attribute besides name just modify the sortJsonName() function.

, ,