Trying to find the easiest way to sort nested json data. Everything I've tried up to this point seems to fail. I'm using Python 2.7 and attempting to sort by name attribute. Here's one of the many python samples I tried:
def sort_json(self,json_data):
data_obj = json.dumps(json_data,sort_keys=True)
return sorted(data_obj["data"]["workflows"]["allWorkflows"],
key=lambda d: d["name"])
Here's a sample of the unsorted json:
{
"data": {
"workflows": {
"allWorkflows": [{
"name": "ICX-SLX Config Basic Support",
"version": 106,
"path": "/Workflows/System/Config/Basic Support/ICX-SLX Config Basic Support"
}, {
"name": "ICX Upgrade Firmware",
"version": 37,
"path": "/Workflows/System/Inventory/Upgrade/ICX Upgrade Firmware"
}, {
"name": "Quarantine_PCAP_Flow",
"version": 357,
"path": "/Workflows/System/Security/Quarantine_PCAP_Flow"
}, {
"name": "ICX-MLX Backup Configuration",
"version": 101,
"path": "/Workflows/System/Inventory/Backup/ICX-MLX Backup Configuration"
}, {
"name": "ICX-SLX-MLX Restart Device",
"version": 15,
"path": "/Workflows/System/Inventory/Restart/ICX-SLX-MLX Restart Device"
}, {
"name": "Revert_Quarantine_End_System",
"version": 169,
"path": "/Workflows/System/Security/Revert_Quarantine_End_System"
}]
}
}
}
Any working examples would be really appreciated.