TechieClues TechieClues
Updated date Feb 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

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

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