How to Read a JSON File in Python?
Hi Friends,
Today, how to read json file in python is our main topic. we will help you to give an example of how to get json file data in python. you will learn how to fetch data from json file in python. step by step explain python read json file example. So, let us see in detail an example.
In this example, we will create one data.json file with some JSON data. Then we will read that file and print in python. we will use open() and JSON load() function to fetch JSON file data. So, let's see a simple example with output:
You can use these examples with python3 (Python 3) version.
Example 1:
I simply created data.json file with content as like below:
data.json
[ { "ID": 1, "Name": "Hardik Savani", "email": "hardik@gmail.com" }, { "ID": 2, "Name": "Vimal Kashiyani", "email": "vimal@gmail.com" }, { "ID": 3, "Name": "Harshad Pathak", "email": "harshad@gmail.com" } ]
main.py
import json # Opening JSON file f = open('data.json') # Get JSON Data from Object data = json.load(f) # Get JSON Data ROW for row in data: print(row) # Closing file f.close()
Output:
{'ID': 1, 'Name': 'Hardik Savani', 'email': 'hardik@gmail.com'} {'ID': 2, 'Name': 'Vimal Kashiyani', 'email': 'vimal@gmail.com'} {'ID': 3, 'Name': 'Harshad Pathak', 'email': 'harshad@gmail.com'}
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Read CSV File Specific Column Example
- How to Get Column Names from CSV File in Python?
- Python Read CSV File Without Header Example
- How to Read a CSV File in Python?
- How to Write CSV File in Python?
- How to Add Header in CSV File using Python?
- Python Write CSV File from List Example
- How to Check If a List is Empty or Not in Python?
- Python Create Text File If Not Exists Example
- How to Add Element to a List in Python?
- How to Get Min Value from Python List?
- Python Create Zip Archive from Directory Example
- How to Add Hours to Date in Python?