How can I create an ordered dictionary from json in Python -
i posting form , grabbing json form dict .
myd = \ {'a': {'b': 'c1', 'd': 'f1'}, 'b': {'bb': 'c2', 'dd': 'f2'}, 'c': {'bbb': 'c3', 'ddd': 'f3'} }
now using josn.loads convert python dict
i doing this
headers = defaultordereddict(list, json.loads(request.post.get('myd')))
can ordered, default dict in python?
after doing order of dict gets changed this
myd = \ {'a': {'b': 'c1', 'd': 'f1'}, 'c': {'bbb': 'c3', 'ddd': 'f3'}, 'b': {'bb': 'c2', 'dd': 'f2'}, }
how can maintain order?
i believe should do:
json.loads(request.post.get('myd'), object_pairs_hook=collections.ordereddict)
you can see documentation object_pairs_hook keyword in documentation.
Comments
Post a Comment