I need to do a complete recursive alphabetical ordering on a JSON object in python.
The reason is to be able to diff two json files.
Given this input:
{
"request-id": "12345",
"version": "1.1.4",
"multi": {
"one": 1,
"two": 2.0,
"Abc": [3,2,4,1, null],
"three": null,
"list": [
{"lb1": 2.1},
{"lb": 2.2},
{"la": 3},
{"mix_list": [1, {"bb":1}, 2, {"aa":1}]}]
}
}
this is the expected output:
{
"multi": {
"Abc": [1,2,3,4,null],
"list": [
{"la": 3},
{"lb": 2.2},
{"lb1": 2.1},
{ "mix_list": [1, 2, {"aa": 1}, {"bb": 1}] }
],
"one": 1,
"three": null,
"two": 2.0
},
"request-id": "12345",
"version": "1.1.4"
}
EDIT: to be able to do a diff it should order the array elements too.
question from:
https://stackoverflow.com/questions/65886581/how-to-completely-sort-a-json-tree-alphabetically 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…