Want to process a json file.There are many objects in this result. At present, the order of these objects is messy. I want to sort these objects according to the value of start, from small to large.
import jsonimport operatorwith open('lab2G05.json','r',encoding='utf8')as fp: json_datas = json.load(fp)for json_data in json_datas: for item in json_data["annotations"][0]["result"]: start = item["value"]["start"] # print(start) # result is a list, and now I want to sort this list.How to get result in result?sort_start = sorted(result, key=operator.itemgetter(start), reverse=False) # I want to sort these items in result according to start from small to large.But now it's in result, I don't know how to get result, and then according to start to sort
sort_start = sorted(result, key=operator.itemgetter(start), reverse=False)
NameError: name 'result' is not defined
Transfer result to item
Get this error
sort_start = sorted(item, key=operator.itemgetter(start), reverse=False)IndexError: string index out of range
These objects in the result in the source file can be sorted according to the start value from small to large.