Sascha
Sascha

Reputation: 10347

Ignore capitalization of letters set through JsonPropertyAttribute

I have a class with three simple properties:

public class NewCard {
    [JsonProperty( "name" )]
    public string Name { get; set; }

    [JsonProperty( "desc" )]
    public string Desc { get; set; }

    [JsonProperty( "idList" )]
    public string IdList { get; set; }
}

I expected a result like this:

{"name":"A name","desc":"","idList":"listId"}

Unfortunately, the result I get looks like this:

{"Name":"A name","Desc":"","IdList":"listId"}

The remote service rejects the json, so I really need to have them lowered. JSON.NET Version: 4.5.6 downloaded using NuGET.

Upvotes: 1

Views: 524

Answers (1)

L.B
L.B

Reputation: 116168

I get the result as you expect when I serialize as

var json = JsonConvert.SerializeObject(new NewCard() {Name="A Name",Desc="A Desc",IdList="ids" });

Upvotes: 1

Related Questions