2

How can I change the way Newtonsoft JSON.NET serializes property names of objects?

2 Answers 2

3

A couple of ways:

  1. You can manually control how it serializes using the JsonTextWriter class:
  2. You could implement a custom JsonConverter that does what you want:
Sign up to request clarification or add additional context in comments.

Comments

2

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

Good one though it is not was I needed. I can use it when migrating JSON to a new "schema" :). Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.