.load()
Published May 4, 2022Updated Jun 15, 2022
Contribute to Docs
The .load()
function decodes a JSON file and returns a Python object. The decoding conversion is based on the following table. The .loads()
function, alternatively, takes a JSON string and returns a Python object.
Syntax
json.load(json_file)
json.loads(json_string)
Example
The json
library can be used to encode and decode a dictionary:
import jsonfoo = {'first':'hello', 'second':'world'}bar = json.dumps(foo)print(type(bar))eggs = json.loads(bar)print(type(eggs))
The output will look like this:
<class 'str'><class 'dict'>
Codebyte Example
The .load()
function can be used to convert a JSON file to 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
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly90 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours