The Wayback Machine - https://web.archive.org/web/20240118183529/https://www.geeksforgeeks.org/json-load-in-python/
Open In App
Related Articles

json.load() in Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The full-form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called json. To use this feature, we import the json package in Python script. The text in JSON is done through quoted-string which contains the value in key-value mapping within { }. It is similar to the dictionary in Python.

Note: For more information, refer to Working With JSON Data in Python

json.load()

json.load() takes a file object and returns the json object. A JSON object contains data in the form of key/value pair. The keys are strings and the values are the JSON types. Keys and values are separated by a colon. Each entry (key/value pair) is separated by a comma.

Syntax :

json.load(file_object)

Argument : It takes file object as a parameter.

Return : It return json object.

Example: Let’s suppose the JSON looks like this.

pyhton-append-json1

We want to read the content of this file. Below is the implementation.




# Python program to read
# json file
   
   
import json
   
# Opening JSON file
f = open('data.json',)
   
# returns JSON object as 
# a dictionary
data = json.load(f)
   
# Iterating through the json
# list
for i in data['emp_details']:
    print(i)
   
# Closing file
f.close()


Output:

python-read-json-output1

Here, we have used the open() function to read the JSON file. Then, the file is parsed using json.load() method which gives us a dictionary named data.

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 23 Mar, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials