json.load()


Youtube Live session on Tkinter

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
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    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 FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer