Hi

Writing JSON to a File using C#

 using System;

using System.IO;

using Newtonsoft.Json;


class Program

{

    static void Main()

    {

        var person = new { Name = "John Doe", Age = 30, City = "New York" };

        string json = JsonConvert.SerializeObject(person, Formatting.Indented);


        File.WriteAllText("data.json", json); // Write JSON to a file

        Console.WriteLine("JSON file written successfully!");

    }

}


Previous
Next Post »