I have a big JSON file that contains timezones like the following:
{
"timezones":[
{
"id":1,
"name":"(UTC) Coordinated Universal Time",
"utc_offset":"+0"
},
{
"id":2,
"name":"(UTC+8:45) Australian Central Standard Time",
"utc_offset":"+8:45"
},
{
"id":3,
"name":"(UTC-5) Acre Time",
"utc_offset":"-5"
},
{
"id":4,
"name":"(UTC+8:45) Australian Central Western Standard Time",
"utc_offset":"+8:45"
}
]
}
I'm trying to sort it according to the utc_offset values from - to +, if the utc_offset are identical, then by name alphabetically. So The wanted result should be like this:
{
"timezones":[
{
"id":3,
"name":"(UTC-5) Acre Time",
"utc_offset":"-5"
},
{
"id":1,
"name":"(UTC) Coordinated Universal Time",
"utc_offset":"+0"
},
{
"id":2,
"name":"(UTC+8:45) Australian Central Standard Time",
"utc_offset":"+8:45"
},
{
"id":4,
"name":"(UTC+8:45) Australian Central Western Standard Time",
"utc_offset":"+8:45"
}
]
}
Using the following code I tried:
lines = lines.sort(int(json['timezones']['utc_offset']), reverse=True)
print(lines)
But it's showing an error AttributeError: 'dict' object has no attribute 'sort'
How I may do this?