Google News
logo
Convert from JSON to Python
To convert a JSON string to a Python object, you can use the `json` module in Python. The `json.loads()` function can be used to parse a JSON string and convert it into a Python object. Here is an example :
Program :
import json

json_str = '{"name": "John", "age": 30, "city": "New York"}'
py_obj = json.loads(json_str)

print(py_obj)
Output :
{'name': 'John', 'age': 30, 'city': 'New York'}
In this example, we first import the `json` module. We then define a JSON string `json_str`. We then use the `json.loads()` function to convert the JSON string into a Python object and assign it to the variable `py_obj`.

Finally, we print the Python object using the `print()` function.