I would recommend Json.Net , see example below:
List<data> _data = new List<data>(); _data.Add(new data() { Id = 1, SSN = 2, Message = "A Message" }); string json = JsonConvert.SerializeObject(_data.ToArray());
Or a slightly more efficient version of the above code (doesn't use a string as a buffer):
//open file stream using (StreamWriter file = File.CreateText(@"D:\path.txt")) { JsonSerializer serializer = new JsonSerializer(); //serialize object directly into file stream serializer.Serialize(file, _data); }
Documentation: Serialize JSON to File
Why? It compares a comparison of conventional serializers as well as test cases โ .
The following is a graph of performance taken from a related article:

This separate post indicates that:
Json.NET has always been efficient in terms of memory, streaming reading and writing large documents, rather than loading them completely into memory, but I was able to find a couple of key places where you could reduce the allocation of objects ...... (now) Json.Net (6.0) allocates 8 times less memory than JavaScriptSerializer
โก.
โ The tests look like Json.Net 5, the current version (when recording) is 10. What version of standard .Net serializers is not mentioned
โก These tests are obviously from developers who support this library. I have not confirmed my claims . If in doubt, check them out yourself.
Liam Jun 04 '13 at 15:25 2013-06-04 15:25
source share