How to write a JSON file in C#?

I need to write the following data into a text file using JSON format in C#. The brackets are important for it to be valid JSON format.

[
  {
    "Id": 1,
    "SSN": 123,
    "Message": "whatever"

  },
  {
   "Id": 2,
    "SSN": 125,
    "Message": "whatever"
  }
]

Here is my model class:

public class data
{
    public int Id { get; set; }
    public int SSN { get; set; }
    public string Message { get; set;}
}

4 Answers
4

Leave a Comment