Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of Newtonsoft.Json's / Json.Net's JsonProperty field in System.Text.Json?

I wanted to know what the euqivalent of the Newtonsoft.Json's / Json.Net's JsonProperty field in System.Text.Json is.

Example:

using Newtonsoft.Json;

public class Example
{
    [JsonProperty("test2")]
    public string Test { get; set; }
}

References:

  • Newtonsoft.Json JsonProperty
  • Using Newtonsoft.Json attributes
like image 424
FranzHuber23 Avatar asked Oct 20 '19 17:10

FranzHuber23


People also ask

Which is better Newtonsoft JSON or System text JSON?

Json does case-insensitive property name matching by default. The System. Text. Json default is case-sensitive, which gives better performance since it's doing an exact match.

Is JSON NET and Newtonsoft JSON same?

Newtonsoft is the creator/publisher (the company), and JSON.NET is the product name. It's the same thing.

What is Jsonproperty attribute in C#?

Instructs the JsonSerializer to always serialize the member with the specified name. Attribute. Newtonsoft.Json.


1 Answers

Just in case, anyone else falls over this. The property is renamed to JsonPropertyName and comes from System.Text.Json.Serialization in the System.Text.Json nuget package.

Example:

using System.Text.Json.Serialization;

public class Example
{
    [JsonPropertyName("test2")]
    public string Test { get; set; }
}

References:

  • Try the new System.Text.Json APIs
  • JsonProperty.Name Property --> Not yet documented properly...
like image 164
FranzHuber23 Avatar answered Sep 20 '22 05:09

FranzHuber23