Serializing Object Graphs with JSON
Explore how to serialize and deserialize object graphs to JSON in C# using both Newtonsoft.Json and the high-performance System.Text.Json API. Learn how to add package references, write JSON files, and compare file sizes between JSON and XML. Understand when to choose each library based on features and performance.
We'll cover the following...
One of the most popular .NET libraries for working with the JSON serialization format is Newtonsoft.Json known as Json.NET. It is mature and powerful.
Newtonsoft.Json
Newtonsoft.Json is so popular that it overflowed the bounds of the 32-bit integer used for the download count in the NuGet package manager, as shown in the following tweet in the figure:
Let’s see it in action:
Step 1: In the WorkingWithSerialization project, add a package reference for the latest version of Newtonsoft.Json, as shown in the ...