how to create json file in python

Solutions on MaxInterview for how to create json file in python by the best coders in the world

showing results for - "how to create json file in python"
Klara
23 Jan 2018
1#import the json module
2import json 
3
4#create a dictionary which we can add to a json file
5dictionary ={ 
6    "name" : "sathiyajith", 
7    "rollno" : 56, 
8    "cgpa" : 8.6, 
9    "phonenumber" : "9976770500"
10} 
11
12#open an object with following inputs: 'name_of_file.json', 'w'
13#dump the content fromt he dictionary into the outfile
14with open("sample.json", "w") as outfile: 
15    json.dump(dictionary, outfile)