json module

The Python standard library module that converts between Python values and JSON text.

In more detail

json.dumps turns a value into a JSON string and json.loads parses one back, while json.dump and json.load do the same with files. Dictionaries become objects, lists and tuples become arrays and None becomes null. Tuples come back as lists, dictionary keys become strings, and values such as sets and dates must be converted before saving.

Examples

json.dumps({"id": 42}).encode()
import json
text = json.dumps({"a": [1, 2]}, indent=2)
json.loads(text)

Related terms

Taught in

References

Certification courses