1using System.Text.Json;
2using System.Text.Json.Serialization;
3
4List<data> _data = new List<data>();
5_data.Add(new data()
6{
7 Id = 1,
8 SSN = 2,
9 Message = "A Message"
10});
11
12using FileStream fileStream = File.Create(@"D:\path.json");
13await JsonSerializer.SerializeAsync(createStream, _data);
14
1//open file stream
2using (StreamWriter file = File.CreateText(@"D:\path.txt"))
3{
4 JsonSerializer serializer = new JsonSerializer();
5 //serialize object directly into file stream
6 serializer.Serialize(file, _data);
7}