This code snippet shows how to read a JSON file (JSON stands for JavaScript Object Notation, ) in python. We can use json.load()
method to read a JSON file in python. In the below example, we use emp_details.json
file which contains JSON objects.
JSON File (emp_details.json):
{
"name": "Sabari",
"Country": "India",
"languages": ["English", "Tamil", "Hindi"]
}
First, we need to import the JSON module and use open()
method to open the file and json.load()
is used to read and parse the JSON file and provides the dictionary named data as shown below,
import json
with open(r'D:\emp_details.json') as f:
data = json.load(f)
print(data)
Output:
{'name': 'Sabari', 'Country': 'India', 'languages': ['English', 'Tamil', 'Hindi']}
Comments (0)