Load JSON File in Python using load() function, but before that let’s have breif about the JSON.
Why JSON? What is a JSON File? What are the Advantages of Using a JSON File?
JSON is used to transfer data between different servers or from server to browser or browser to server. JSON is human readable format and it’s lightweight and easy to parse.
How to Read a JSON File in Python
Create a JSON file using sample data. Please use this data to create JSON file.
Here is an example of Python code which loads JSON file and print the data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
importjson# Opening JSON filef =open('data.json')
# returns JSON object as# a dictionarydata = json.load(f)
# Iterating through the json# listfor i in data['emp_details']:
print(i)
# Closing filef.close()
json.load
If you are a python programmer, json.load is a handy function to load data from a json file. It returns JSON Object after reading and parsing the JSON File data.
Sharing is caring!