Use Newtonsoft.Json in .NET Core 3 Web Api

October 22, 2020 .net .netcore asp.net

This post is mostly just distilling information I got from .NET Core Tutorials to revert back to Newtonsoft.Json in asp.net core WebApi.

In your csproj add the PackageReference:

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
</ItemGroup>

And then in the ConfigureServices of the Startup class add the .AddNewtonsoftJson() after the call to .AddControllers():

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers().AddNewtonsoftJson();
}