Search code examples
asp.net-mvcasp.net-web-apijsonserializer

WebApi jsonFormatter how to change Null String values to Empty String


Im receiving quirky issues with my json data from my asp.net MVC WebApi coming into my kendoUI controls because null strings are being sent across as

"FielName":null

Im wondering how do I go about setting up the jsonformatter on my webapi so that string fields with a null value return empty string "" instead of Null like? So looks like.

"FieldName":""

Thanks


Solution

  • You can look to modify the JsonFormatter and change it's ContractResolver to be something a little different. This question: Serializing null in JSON.NET looks like it could be easily adapted for your purposes (just by updating the default JsonFormatter).