Issue
I have the following string that I need to sterilize with json.dumps
, and then convert to list with json.loads
.
The problem is that I cannot convert it to a list after json.dumps
.
I even tried with ast.literal_eval()
.
The data type remains string:
test1 = """[{"key":"value","found":"false","matches":"","correction":""},
{"keyb":"valueb","found":"false","matches":"","correction":""}]"""
a=json.dumps(test1)
b=json.loads(a)
print(type(b)) # str
Solution
Try eval
test1 = """[{"key":"value","found":"false","matches":"","correction":""},
{"keyb":"valueb","found":"false","matches":"","correction":""}]"""
x = eval(test1)
print(x, type(x))
[{'key': 'value', 'found': 'false', 'matches': '', 'correction': ''}, {'keyb': 'valueb', 'found': 'false', 'matches': '', 'correction': ''}] <class 'list'>
Answered By - Abhi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.