TutorialClues TutorialClues
Updated date Mar 23, 2021
How to Read a JSON File in Python

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']}

ABOUT THE AUTHOR

TutorialClues
TutorialClues
Software Professional, India

IT professional with 14+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.tutorialclues.com/profile/tutorialclues

Comments (0)

There are no comments. Be the first to comment!!!