Python | Sort JSON by value Last Updated : 12 Feb, 2019 Comments Improve Suggest changes Like Article Like Report Let's see the different ways to sort the JSON data using Python. What is JSON ? JSON (JavaScript Object Notation) is a lightweight, text-based, language-independent data exchange format that is easy for humans and machines to read and write. JSON can represent two structured types: objects and arrays. An object is an unordered collection of zero or more name/value pairs. An array is an ordered sequence of zero or more values. The values can be strings, numbers, booleans, null, and these two structured types. The task is to sort the JSON first by code, then by grade and then by enrollment_no . Code #1: Sorting in Desc order Python3 1== # Python code to demonstrate sorting in JSON. import json data='''{ "Student":[ { "enrollment_no":"9915103000", "name":"JIIT", "subject":[ { "code":"DBMS", "grade":"C" } ] }, { "enrollment_no":"8815103057", "name":"JSS", "subject":[ { "code":"COA", "grade":"A" }, { "code":"CN", "grade":"A+" } ] } ] }''' # Parsing Json object json_parse = json.loads(data) # iterating for it in json_parse['Student']: for y in it['subject']: print(y['code'],y['grade'],it['enrollment_no'],it['name']) Output : DBMS C 9915103000 JIIT COA A 8815103057 JSS CN A+ 8815103057 JSS Code #2 : By using External library such as Pandas (Sorting in Ascending order). Python3 from pandas.io.json import json_normalize df = json_normalize(json_parse['Student'], 'subject', ['enrollment_no', 'name']) df.sort_values(['code', 'grade', 'enrollment_no']).reset_index(drop=True) Output: code grade enrollment_no name 0 CN A+ 8815103057 JSS 1 COA A 8815103057 JSS 2 DBMS C 9915103000 JIIT Comment More infoAdvertise with us Next Article Python | Sort JSON by value everythingispossible Follow Improve Article Tags : Python Python Programs JSON Practice Tags : python Similar Reads Sort Python Dictionary by Value Python dictionaries are versatile data structures that allow you to store key-value pairs. While dictionaries maintain the order of insertion. sorting them by values can be useful in various scenarios. In this article, we'll explore five different methods to sort a Python dictionary by its values, a 3 min read Python - Sort Nested keys by Value Sometimes, while working with data records, we can have a problem in which we need to perform the sorting of nested keys of dictionary by the value of occurrence. This can have applications in arranging scores, prices etc. Lets discuss a way in which this task can be performed. Method #1 : Using sor 3 min read Python JSON Sort In the world of programming, managing and manipulating data is a fundamental task. JSON (JavaScript Object Notation) is a widely used data interchange format due to its simplicity and human-readable structure. When working with JSON data in Python, sorting becomes essential for better organization a 3 min read Python - Sort List by Dictionary values Sometimes while working with a Python dictionary, we can have problems in which we need to perform a sort of list according to the corresponding value in the dictionary. This can have applications in many domains, including data and web development. Let's discuss certain ways in which this task can 3 min read Sort Dictionary by Value Python Descending Sometimes, we need to sort the dictionary by value in reverse order or descending order. We can perform this task easily by using Python. In this article, we will learn to Sort the Dictionary by Value in Descending Order using Python Programming. Below is an example to understand the problem stateme 4 min read Python - Sort Dictionary by Values and Keys Given a dictionary, sort according to descended values, if similar values, then by keys lexicographically. Input : test_dict = {"gfg" : 1, "is" : 1, "best" : 1, "for" : 1, "geeks" : 1} Output : {"best" : 1, "is" : 1, "for" : 1, "geeks" : 1, "gfg" : 1} Explanation : All values are equal, hence lexico 3 min read Python - Sort Dictionary by Values Summation Give a dictionary with value lists, sort the keys by summation of values in value list. Input : test_dict = {'Gfg' : [6, 7, 4], 'best' : [7, 6, 5]} Output : {'Gfg': 17, 'best': 18} Explanation : Sorted by sum, and replaced. Input : test_dict = {'Gfg' : [8], 'best' : [5]} Output : {'best': 5, 'Gfg': 4 min read Python - Sort Dictionary by Value Difference Sometimes, while working with Python dictionaries, we can have problem in which in which we need to perform sorting of items on basis of various factors. One such can be on basis of absolute difference of dual value list. This can occur in Python > 3.6, as dictionaries are ordered. This kind of p 3 min read Sort a Nested Dictionary by Value in Python Sorting a nested dictionary in Python involves understanding its structure, defining sorting criteria, and utilizing the `sorted()` function or `.sort()` method with a custom sorting function, often a lambda. This process is essential for organizing complex, hierarchical data efficiently. Mastery of 3 min read Python | Sort dictionary by value list length While working with Python, one might come to a problem in which one needs to perform a sort on dictionary list value length. This can be typically in case of scoring or any type of count algorithm. Let's discuss a method by which this task can be performed. Method 1: Using sorted() + join() + lambda 4 min read Like