Shreyansh Lodha
Shreyansh Lodha

Reputation: 83

Python 3 - How to convert a string to a list of dictionary

I have the data coming as a API which is in a string format And the data is exactly like list of dictionaries

'{'key1':'value','key2':'value','key3':'value'},{'key1':'value','key2':'value','key3':'value'},...'

Is their any way I can convert this string to a list of dictionary?

Upvotes: 0

Views: 933

Answers (1)

Mureinik
Mureinik

Reputation: 312146

ast.literal_eval should do the trick:

from ast import literal_eval
result = literal_eval(my_string)

Upvotes: 1

Related Questions