using System.Text.Json;
using System.Text.Json.Serialization;
List<data> _data = new List<data>();
_data.Add(new data()
{
Id = 1,
SSN = 2,
Message = "A Message"
});
string json = JsonSerializer.Serialize(_data);
File.WriteAllText(@"D:path.json", json);
# write json file
import json
d = {
"firstName": "Tom",
"lastName": "Jack",
"gender": "male",
"age": 35,
"address": {
"streetAddress": "126",
"city": "San Jone",
"state": "CA",
"postalCode": "95150"
},
"phoneNumbers": [
{ "type": "home", "number": "4083627627" }
]
}
filename = "/content/sample_data/sample1.json"
with open(filename, 'w') as f:
json.dump(d, f)