I have a Postgres db where OrderedDict
has been saved as a string. I need to convert this string into json/dict so that it can be saved in a JSONField. How can I convert this string into dict?
String example -
OrderedDict([('order_id', 'xxxxxx'), ('tracking_id', 'xxxxxx'), ('bank_ref_no', 'xxxxx'), ('order_status', 'Success')])
I tried json.loads(string)
but it gives a decoding error. Any solution apart from manually parsing the string?
eval(string)
? – Seaborgeval
since it seems unsafe. But in this case I guess it should be okay – Schramkeeval
but usingregex
orsplit()
it would need more work and it would not predict all cases. – Seaborg