Categories
Python Answers

How to convert dictionary to JSON with Python?

Spread the love

Sometimes, we want to convert dictionary to JSON with Python.

In this article, we’ll look at how to convert dictionary to JSON with Python.

How to convert dictionary to JSON with Python?

To convert dictionary to JSON with Python, we can use the json.dumps method.

For instance, we write

import json

r = {'is_claimed': 'True', 'rating': 3.5}
r = json.dumps(r)

to call json.dumps with dict r to convert the dict into a JSON string.

Conclusion

To convert dictionary to JSON with Python, we can use the json.dumps 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 *