using Newtonsoft.Json; public void WriteJsonData() { using (var writer = new JsonTextWriter(new StreamWriter(@"C:\data\file.json"))) { writer.WriteStartArray(); writer.WriteValue(1); writer.WriteValue(2); writer.WriteEndArray(); } }
using Newtonsoft.Json; public void WriteJsonData() { using (var writer = new JsonTextWriter(new StreamWriter(Console.OpenStandardOutput()))) { var array = new[] { "apple", "orange", "banana" }; writer.WriteStartArray(); foreach (var item in array) { writer.WriteValue(item); } writer.WriteEndArray(); } }In this example, a JSON array is created with an array of string elements and then written to the console output. Both of these examples use the Newtonsoft.Json package library.