Json.NET Case-insensitive Property Deserialization

That's a bug.

Case-insensitive property deserialization refers to Json.NET being able to map a JSON property with the name "Key" to either a .NET class's "Key" or "key" member.

The bug is KeyValuePair requires its own JsonConverter but misses out of the case insensitive mapping.

https://github.com/JamesNK/Newtonsoft.Json/blob/fe200fbaeb5bad3852812db1e964473e1f881d93/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs

Use that as a base and add the lower case "key" and "value" to the case statement when reading JSON.


One efficient way I found was to use GetValue with StringComparer parameter.

So for example,

JObject contact;
String strName = contact.GetValue('Name');

You are trying to access 'Name' property as case insensitive, you can use

JObject contact;
String strName = contact.GetValue("ObjType", StringComparison.InvariantCultureIgnoreCase);

Tags:

C#

Json.Net