I have an object model that looks like:
public class Product
{
public string ProductCode { get; set; }
public string ProductInfo { get; set; }
}
I'm populating this via Dapper, and exposing it to an angular.js consumer, but the property names in the JSON are coming out as:
{
"productCode": 1,
"productInfo": "Product number 1"
}
Note in particular the camel-case. I would like it to match the original declared names, i.e.
{
"ProductCode": 1,
"ProductInfo": "Product number 1"
}
How can I do this?
Under the hood, it is most likely that the web-API is using JSON.Net as the JSON serialization engine; this means that you can control the output using JSON.Net's attributes, for example:
Without these, JSON.Net uses conventions and configuration - and the usual JSON convention is to use camel-case, hence that is the default. You can also probably change the default configuration, but I would advise against that unless you understand the scope of the impact.