In this article I will explain with an example, how to use Newtonsoft as JSON Serializer in ASP.Net Core (.Net Core 2.1).
Installing Newtonsoft package using Nuget
Configuring Newtonsoft library
In order to configure Newtonsoft library in ASP.Net Core, please follow the below steps.
1. Open the Startup.cs file from the Solution Explorer window.
2. Inherit the following namespace.
using Newtonsoft.Json.Serialization;
3. Then, inside the ConfigureServices method, you will have to add the following code which will instruct the program to use Newtonsoft library for JSON serialization.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
}
Other available versions