Json Property Names in Dotnet Core 3.x

TL;DR

Pre-Dotnet Core 3.0 uses the format below to map incoming json properties to C# model properties

#
1
2
3
4
5
6
public class Model
{
[JsonProperty("first_name")]
public string FirstName

}

Dotnet Core 3.x now uses

#
1
2
3
4
5
6
public class Model
{
[JsonPropertyName("first_name")]
public string FirstName

}

Attempting to use the first version in a Dotnet Core 3.x Application will fail to bind and those properties will be null.

What Changed

Newtonsoft.Json, the Json Library has been removed from the ASP.Net Core Shared Framework in favour or the new System.Text.Json library. Since the JsonProperty attribute is from the Newtonsoft.Json library, removing it from ASP.Net Core means it can no longer bind property names.

The new added Json API’s is claimed to specifically designed for high-performance scenarios so defintiely check it out.

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×