Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sort json python

import pprint
# Array of JSON Objects
products = [{"name": "HDD", "brand": "Samsung", "price": "$100"},
            {"name": "Monitor", "brand": "Dell", "price": "$120"},
            {"name": "Mouse", "brand": "Logitech", "price": "$10"}]
'''
Print the sorted JSON objects in descending order
based on the price key value
'''
print("
Array of JSON objects after sorting:")
products = sorted(products, key=lambda k: k['price'], reverse=True)
pprint.pprint((products))
 
PREVIOUS NEXT
Tagged: #sort #json #python
ADD COMMENT
Topic
Name
5+1 =