JSon Serializing with lowercase properties (JSon.Net)

With JSon.Net we can define a custom ContractResolver to be able to serialize a C# object to a JSon with lowercase property names.

public string GenerateJSon(MyObjectClass myObject)
    return JsonConvert.SerializeObject(myObject, Formatting.None,
        new JsonSerializerSettings
            ContractResolver = new LowercaseContractResolver()
private class LowercaseContractResolver : DefaultContractResolver
    protected override string ResolvePropertyName(string propertyName)
        return propertyName.ToLower();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s