I am struggling with the following problem:
I want to convert an OrderedDict
like this:
OrderedDict([(\'method\', \'constant\'), (\'data\', \'1.
If you are looking for a recursive version without using the json
module:
def ordereddict_to_dict(value):
for k, v in value.items():
if isinstance(v, dict):
value[k] = ordereddict_to_dict(v)
return dict(value)
Its simple way
>>import json
>>from collection import OrderedDict
>>json.dumps(dict(OrderedDict([('method', 'constant'), ('data', '1.225')])))