How to parse data in JSON format with Python?

Sometimes, we want to parse data in JSON format with Python.

In this article, we’ll look at how to parse data in JSON format with Python.

How to parse data in JSON format with Python?

To parse data in JSON format with Python, we can use the json.loads method.

For instance, we write:

import json

data = json.loads('{"one" : "1", "two" : "2", "three" : "3"}')
print(data['two'])

We import the json module and call the json.loads method with a JSON string.

It returns a dictionary with the keys being the JSON object’s keys and the values being the JSON object’s values and we assign that to data.

Therefore, we see 2 printed.

Conclusion

To parse data in JSON format with Python, we can use the json.loads method.