I have a json object which is returned against a post call
r = requests.post("url", json=data)
I was doing r.json()
to get the json object. But as I understand it creates a dict object which is unordered. I need to preserve the order.
I saw the solution described here: Items in JSON object are out of order using "json.dumps"?
But my challenge is my starting point is a response object. How do I take it and convert to a json with the order preserved?
Adding some more details:
My API call returns an object of form:
[{
"key01": "value01",
"key02": "value02",
"keyN": "valueN"
},
{
"key01": "value01",
"key02": "value02",
"keyN": "valueN"
},
{
"key01": "value01",
"key02": "value02",
"keyN": "valueN"
}
]
I have a table with three columns as key01,key02 and keyN.
I need to post this json object after some minor manipulations to a software maintaining that specific order of key01,key02 and keyN.
But as soon as I do response.json() it is changing the order. I have tried to use the orderedlist approach as mentioned in the two other threads but so far my object is looking like this:
b"OrderedDict([('key01','value01'),('key02','value02'),('keyN','valueN')])
How do I get a json which looks like this instead: {"key01":"value01","key02":"value02","keyN":"valueN"}