I have this kind of data:
{
"Item 1": {
"Purchased": {
"quantity": "5.000",
"cost": "80.000"
},
"Rent": {
"quantity": "45.000",
"cost": "25200.000"
}
},
"Item 2": {
"Purchased": {
"quantity": "35.000",
"cost": "25000.000"
},
"Rent": {
"quantity": "0.0",
"cost": "0.0"
}
},
"Item 3": {
"Rent": {
"quantity": "25.000",
"cost": "50.000"
},
"Purchased": {
"quantity": "0.0",
"cost": "0.0"
}
},
"Item 4": {
"Rent": {
"quantity": "5.000",
"cost": "80.000"
},
"Purchased": {
"quantity": "0.0",
"cost": "0.0"
}
}
}
The data is printed into a prepared template. Leaving it aside, what I want is for the "Purchased" and "Rent" sections of each item to be alphabetically sorted. Items 1 and 2 are proper here but items 3 and 4 are not. The issue is that from the server items can come with different kinds of data. For e.g. Item 2 came only with Purchased, so a Rent component with 0,0 was added.
I have seen a few string sorting functions here on so but they are for single arrays and I have failed to adopt them here.