make a json file code example
Example 1: how to create json file in python
#import the json module
import json
#create a dictionary which we can add to a json file
dictionary ={
"name" : "sathiyajith",
"rollno" : 56,
"cgpa" : 8.6,
"phonenumber" : "9976770500"
}
#open an object with following inputs: 'name_of_file.json', 'w'
#dump the content fromt he dictionary into the outfile
with open("sample.json", "w") as outfile:
json.dump(dictionary, outfile)
Example 2: how to create json file in c#
using (StreamWriter file = File.CreateText(@"D:\path.txt"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, _data);
}
Example 3: how to set up a json file
{
"name" : "data"
}