Python JSON Module
Published May 4, 2022Updated Sep 29, 2022
Contribute to Docs
The json module provides tools for working with the JavaScript Object Notation (JSON) format. It can be imported with the following line:
import json
JSON in Python is based on the object-literal syntax of JavaScript. The following Python data types can be converted to JSON strings in Python:
- Booleans (
booltype) - Dictionaries (
dicttype) - Number types (i.e.,
intandfloat) - Sequence types (i.e., lists and tuples)
- Strings (
strtype) NoneType
The following functions are provided by the json module:
JSON Module
- .dump()
- Encodes a Python object as a JSON file.
- .load()
- Parses JSON data from a file-like object and converts it into a Python object.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
- Includes 27 Courses
- With Professional Certification
- Beginner Friendly.95 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours