How can i convert the below string to JSON using python?
str1 = "{'a':'1', 'b':'2'}"
See Question&Answers more detail:osHow can i convert the below string to JSON using python?
str1 = "{'a':'1', 'b':'2'}"
See Question&Answers more detail:osThe json
library in python
has a function loads
which enables you to convert a string (in JSON format) into a JSON. Following code for your reference:
import json
str1 = '{"a":"1", "b":"2"}'
data = json.loads(str1)
print(data)
Note: You have to use '
for enclosing the string, whereas "
for the objects and its values.