Reputation: 133
I'm hoping someone could help me with this problem. I have a string that looks this way
a = '[{"name": "bob", "age":"11", "participantid":"Me", "sentiment":"NEUTRAL", "content":"Hey, how you doing."}, {{"name": "Roland", "age":"16", "participantid":"boy", "sentiment":"NEUTRAL", "content":"Hey, I'm doing good and you?."}]'
And my goal is to return the list instead of string, so I'm expecting something like this:
a = [{"name": "bob", "age":"11", "participantid":"Me", "sentiment":"NEUTRAL", "content":"Hey, how you doing."}, {{"name": "Roland", "age":"16", "participantid":"boy", "sentiment":"NEUTRAL", "content":"Hey, I'm doing good and you?."}]
I've been stuck on this for a while, I've used replace and strip, but none works.
Thanks for your help.
Upvotes: 0
Views: 54
Reputation: 87401
Try this:
import json
print(json.loads(a))
Or this:
import ast
print(ast.literal_eval(a))
Upvotes: 2