using Newtonsoft.Json; var product = new Product { Id = 1, Name = "Smartphone", Price = 799.99m }; string json = JsonConvert.SerializeObject(product, Formatting.Indented); Console.WriteLine(json);