json.load()

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

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()
load() to write Json data to file


plus2net.com



Post your comments , suggestion , error , requirements etc here




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