I have an array similar to this one in a JSON file.
data = {
"foo" : {
"08" : {"bar": "1", "baz":"2"},
"09" : {"bar": "3", "baz":"10"},
"10" : {"bar": "5", "baz":"3"},
"11" : {"bar": "8", "baz":"8"},
"12" : {"bar": "9", "baz":"8"}
},
"foo_2" : {
"01" : {"bar": "1", "baz":"2"},
"02" : {"bar": "1", "baz":"2"}
//03, 04 and so on..
}
}
Let's say I want to get the objects from the first foo key, so using data.foo
will do just fine.
Now, when iterating through data.foo
, the indexes will not come in the order shown on the file. I think it's due to the fact the indexes are strings instead of numbers, but still, they'll come in the following order:
{
"12" : {"bar": "9", "baz":"8"},
"11" : {"bar": "8", "baz":"8"},
"10" : {"bar": "5", "baz":"3"},
"08" : {"bar": "1", "baz":"2"},
"09" : {"bar": "3", "baz":"10"}
}
Tried many things here and did a lot of reasearch here in SO but found few topics on the subject and they all will sort the array based in a value deep inside the array, like bar
for example.
how would you sort this array only by those first numbered indexes, so they come out just like they're organized in the file ?