I’m using Newtonsoft JSON.NET 4.5r7 in an MVC4 non-api project.
Below I rename “id” to DT_RowId for DataTables “mDataProp”, but also want to change the data, e.g. 42 becomes “row_42” during serialization.
sealed public class Species
{
[JsonProperty("DT_RowId")]
public long id { get; private set; } // Change me to row_{n}
public int amu { get; private set; }
public string chemicalFormula { get; private set; }
...
}
The documentation is a little hard to follow for someone not familiar with the library, and examples are lacking.
I can add a “row_n” property to each class, but coupling the view with the model is evil™
The question is: How to I alter the serialized data with JSON.net to achieve this result?
From the action instead of returning the model you could easily create an anonymous object using linq query and return it.