json.load(): parses JSON data from a file-like object

By using file object in Python we can read Json formatted data from a file using load() method.

Getting a List
import json
fob=open('data_j3.txt','r')
print(json.load(fob)) # ['Alex', 'Ronald', 'Ronny']
fob.close()
Getting a Dictionary
import json
with open("data_j2.json", "r") as fob:
    print(json.load(fob)) # {'1': 'Alex', '2': 'Ronald', '3': 'Ronny'}
fob.close()
import json
fob=open('data_j.txt','r')
print(json.load(fob)) # {'1': 'Alex', '2': 'Ronald'}
fob.close()

Sample text files

We used all the files created by using the code given at dump() tutorial. Same files can be used for above code.
fob=open('data_j2.json','r')
print(fob.read()) # {"1": "Alex", "2": "Ronald", "3": "Ronny"}
fob.close()

From URL to Json

import json
from urllib.request import urlopen
url="https://www.plus2net.com/php_tutorial/student.json" #Json file
f=urlopen(url)   # open 
data=json.load(f) # data collected 
for row in data:
    print(row)

loads() to write Json data to file
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer