I know that to convert a dictionary to/from a string, I use json.loads
and json.dumps
. However, those methods fail when given a string representing
A well-formed python data type can in most case be interpreted using ast.literal_eval
import ast
ast.literal_eval("[{'topic': 'obama', 'interval': 'daily', 'type': 'test'}, {'topic': 'biden', 'interval': 'immediate', 'type': 'test'}]")
Out[38]:
[{'interval': 'daily', 'topic': 'obama', 'type': 'test'},
{'interval': 'immediate', 'topic': 'biden', 'type': 'test'}]