How can I change the way Newtonsoft JSON.NET serializes property names of objects?
2 Answers
A couple of ways:
- You can manually control how it serializes using the
JsonTextWriterclass: - You could implement a custom
JsonConverterthat does what you want:
Comments
You can create a model with the property names. And change them by creating some private variables that will be use to as return values for the properties. This is will direct the deserializer to reset the name of the property.
private int _privateId;
public int NameThatExistAlreadyInTheJson
{
set { _privateId = value; }
}
public int NameYouWantItToBeDisplayInstead
{
get { return _privateId; }
}
1 Comment
Mihail Shishkov
Good one though it is not was I needed. I can use it when migrating JSON to a new "schema" :). Thanks.