# A quick look at the json module in Python


If you ever need to work with JSON files in Python, you're going to encounter the module with the same name.

It help encode to and decode from JSON. Here are the basics:

➡ json.load imports contents from a JSON file to a Python object, based on conversion rules (object -&gt; dict, array -&gt; list/tuple, string-&gt; str etc)

➡ json.dump performs the opposite operation - export to a file-like object

There are also the json.loads and json.dumps functions (notice the extra s) which apply to strings instead of files.

There's also the *json.tool*, which can validate and pretty-format a provided json file.

You can save that prettified json into another file, as follows:

`python -m json.tool ugly_format.json pretty_format.json`

![](https://miro.medium.com/v2/resize:fit:1400/0*CmsJRPuTkbV13MNz align="left")

*Found it useful? Subscribe to my Analytics newsletter at* [*notjustsql.com*](https://notjustsql.com)*.*

---

*Enjoyed this? Here are some related articles you might find useful:*

- [Retrying in Python using tenacity](https://datawise.dev/retrying-in-python-using-tenacity)
- [Using virtual environments in Python](https://datawise.dev/using-virtual-environments-in-python)
- [Installing Python packages with pip](https://datawise.dev/installing-python-packages-with-pip)
- [Using tempfile module in Python](https://datawise.dev/using-tempfile-module-in-python)

