If you want to change the serialization behavior in Newtonsoft.Json aka JSON.NET, you need to create your own settings:
var jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), NullValueHandling = NullValueHandling.Ignore
You can also pass these settings to JsonConvert.SerializeObject :
JsonConvert.SerializeObject(objectToSerialize, serializerSettings);
For ASP.NET MVC and web API. At Global.asax:
protected void Application_Start() { GlobalConfiguration.Configuration .Formatters .JsonFormatter .SerializerSettings .ContractResolver = new CamelCasePropertyNamesContractResolver(); }
Exclude null values:
GlobalConfiguration.Configuration .Formatters .JsonFormatter .SerializerSettings .NullValueHandling = NullValueHandling.Ignore;
Indicates that null values ββshould not be included in the resulting JSON.
ASP.NET Kernel
The ASP.NET core serializes values ββin camelCase format by default.
Andrei Mar 02 '14 at 16:54 2014-03-02 16:54
source share