How to convert console output to JSON format output using c# code
class Program
{
static void Main(string[] args)
{
Names();
Console.ReadLine();
}
public static void Names()
{
List<Name> names = new List<Name>();
names.Add( new Name() { FName = "Sri",LName="Kumari"});
names.Add(new Name() { FName = "Pavan", LName = "Kumar" });
names.Add(new Name() { FName = "Harish", LName = "Raj" });
foreach (Name item in names)
{
Console.WriteLine(item.FName + "\t" + item.LName);
}
}
}
public class Name
{
public string FName { get; set; }
public string LName { get; set; }
}
Output :
Sri Kumari
Pavan Kumar
Harish Raj
I want to print that console output into JSON format like the below ex:
{
"Name":
[{"FName":"Sri","LName":"Kumari},{"FName":"Sri","LName":"Kumari},{"FName":"Sri","LName":"Kumari}]
}
I'm new to coding.
Any ideas would be appreciated.