EN
Python - convert string to json
0
points
In this article, we would like to show you how to convert string to JSON in Python.
Quick solution:
import json
string = '{"id": 2, "name": "Tom", "age": 25}'
result = json.loads(string)
Practical example
In this example, we use json.loads()
method to convert string to the JSON.
import json
string = '{"id": 2, "name": "Tom", "age": 25}'
result = json.loads(string)
print(result)
print(result["id"], result["name"], result["age"])
Output:
{'id': 2, 'name': 'Tom', 'age': 25}
2 Tom 25