Categories
Python Answers

How to convert JSON string to dict using Python?

Spread the love

Sometimes, we want to convert JSON string to dict using Python.

In this article, we’ll look at how to convert JSON string to dict using Python.

How to convert JSON string to dict using Python?

To convert JSON string to dict using Python, we can use the json.loads method.

For instance, we write

import json

# ...

d = json.loads(j)
print(d['glossary']['title'])

to load the j JSON string into a dict with the json.loads method and assign the returned dict to d.

Then we can get the value we’re looking for from the dict d.

Conclusion

To convert JSON string to dict using Python, we can use the json.loads method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *