How to sorting JSON or Text with Python
This my code
import requests
import json
response = requests.get('https://dataapi.moc.go.th/export-commodity-countries?year=2017&month=12&com_code=101010200&limit=3', verify=False)
json = json.dumps(response.json(), sort_keys=True, indent=4)
print(json)
response from request
[
{
"acc_quantity": 446172.38,
"acc_value_baht": 11962105709.0,
"acc_value_usd": 354576307.0,
"country_code": "US",
"country_name_en": "U.S.A.",
"month": 12,
"quantity": 40907.66,
"year": 2017
},
{
"acc_quantity": 247355.84,
"acc_value_baht": 6308794603.0,
"acc_value_usd": 187646852.0,
"country_code": "CN",
"country_name_en": "CHINA",
"month": 12,
"quantity": 55167.72,
"year": 2017
},
{
"acc_quantity": 179555.35,
"acc_value_baht": 4767877318.0,
"acc_value_usd": 140840413.0,
"country_code": "HK",
"country_name_en": "HONG KONG",
"month": 12,
"quantity": 16576.98,
"year": 2017
},
]
I want to sorting numbers in descending order by "quantity" value from response. please help me advice on how to, thanks