python sort list of json by value

前端 未结 4 1097
北海茫月
北海茫月 2020-12-28 12:33

I have a file consists of JSON, each a line, and want to sort the file by update_time reversed.

sample JSON file:

{ \"page\": { \"url\": \"url1\", \"         


        
4条回答
  •  误落风尘
    2020-12-28 13:05

    # sort json
    lines = sorted(lines, key=lambda k: k['page'].get('update_time', 0), reverse=True)
    

提交回复
热议问题