I've been using Newtonsoft.Json for years. That meant installing Newtonsoft for each project, which now has become virtually every project I create, both work and home. So I was pretty glad to see Microsoft created a built in version first starting with .NET Core 2.0, and now in .NET 5.0: System.Text.Json
System.Text.Json doesn't have complete feature parity with Newtonsoft.Json, but does have a lot of similarity at the basic level, so transitioning is fairly straightforward. I think the only reason to stick with Newtonsoft is if you have a lot of customized serialization behavior. But if you don't, I'd suggest making the switch. System.Text.Json is apparently a bit more performant, and comes built in after .NET 5.0
Here are some simple examples of how to convert existing code:
string asJson = Newtonsoft.Json.JsonConvert.SerializeObject(this);
Now becomes:
string asJson = System.Text.Json.JsonSerializer.Serialize(this);
And for deserializing:
SomeClass instance = Newtonsoft.Json.JsonConvert.DeserializeObject<SomeClass>(asJson);
Now becomes:
SomeClass instance = System.Text.Json.JsonSerializer.Deserialize<SomeClass>(asJson);
Json property attributes also need to change as follows:
class MyClass
{
[Newtonsoft.Json.JsonIgnore]
public int Prop1 { get; set; }
[Newtonsoft.Json.JsonProperty("Property2")]
public int Prop2 { get; set; }
}
Now becomes:
class MyClass
{
[System.Text.Json.Serialization.JsonIgnore]
public int Prop1 { get; set; }
[System.Text.Json.Serialization.JsonPropertyName("Property2")]
public int Prop2 { get; set; }
}