How can i convert the below string to JSON using python?
str1 = "{'a':'1', 'b':'2'}"
The 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With