title: Change Name of 'Key' and 'Value' when using JSON.NET to serialize complex Dictionary
body: <p>I am running into a strange problem with serializing data with json.net. Mainly, I am trying to rename the 'Key' and 'Value' names in the outgoing json to be something more descriptive. Specifically, I want the IRequest related 'Key' to be called 'Request' and the IQuoteTimeSeries 'Value' to be 'DataSeries'</p>
  
  <p>Note, this will not be deserialized. It is only used in data analysis on the web page.</p>
  
  <p>The data repository object I am serializing is a <code>Dictionary&lt;IRequest, IQuoteTimeSeries&gt;</code> object. The IRequest represents a specific request for data and the IQuoteTimeSeries is the object that contains the returning data as a <code>SortedDictionary&lt;DateTime, IQuote&gt;</code>. This is a series of data sorted by timestamp. In this example, I only have one item in the TimeSeries for brevity, but in most cases there would be many items.</p>
  
  <p>Everything needs to be organized together, serialized and sent out to be consumed by JavaScript.  </p>
  
  <p>Here is the basic code for these objects;</p>
  
  <pre><code>[JsonArray]
  public class QuoteRepository : Dictionary&lt;IRequest, IQuoteTimeSeries&gt;, IQuoteRepository
  {
      public QuoteRepository() { }   
  
      public void AddRequest(IRequest request)
      {
          if (!this.ContainsKey(request))
          {
              IQuoteTimeSeries tSeries = new QuoteTimeSeries(request);
              this.Add(request, tSeries);
          }
      }
  
      public void AddQuote(IRequest request, IQuote quote)
      {        
          if (!this.ContainsKey(request))
          {
              QuoteTimeSeries tSeries = new QuoteTimeSeries(request);
              this.Add(request, tSeries);
          }        
          this[request].AddQuote(quote);        
      }    
  
      IEnumerator&lt;IQuoteTimeSeries&gt;  Enumerable&lt;IQuoteTimeSeries&gt;.GetEnumerator()
      {
          return this.Values.GetEnumerator();
      }
  }
  </code></pre>
  
  <p>A quote time series looks like this;</p>
  
  <pre><code>[JsonArray]
  public class QuoteTimeSeries: SortedDictionary&lt;DateTime, IQuote&gt;, IQuoteTimeSeries
  {  
      public QuoteTimeSeries(IRequest request)
      {
          Request = request;
      }
      public IRequest Request { get; }
      public void AddQuote(IQuote quote)
      {
          this[quote.QuoteTimeStamp] = quote;
      }
  
      public void MergeQuotes(IQuoteTimeSeries quotes)
      {
          foreach (IQuote item in quotes)
          {
              this[item.QuoteTimeStamp] = item;
          }
      }
  
      IEnumerator&lt;IQuote&gt; IEnumerable&lt;IQuote&gt;.GetEnumerator()
      {
          return this.Values.GetEnumerator();
      }
  
  }
  </code></pre>
  
  <p>The code used to serialize this is fairly simple:</p>
  
  <pre><code>IQuoteRepository quotes = await requests.GetDataAsync();
  
  JsonSerializerSettings settings = new JsonSerializerSettings
  {
      ContractResolver = QuoteRepositoryContractResolver.Instance,
      NullValueHandling = NullValueHandling.Ignore
  };
  
  return Json&lt;IQuoteRepository&gt;(quotes, settings);
  </code></pre>
  
  <p>I added a contract resolver with the intention of overriding the property writing. The <code>property.PropertyName =</code> code is being hit and the property names are being changed, but the output JSON is unaffected.</p>
  
  <pre><code>public class QuoteRepositoryContractResolver : DefaultContractResolver
  {
      public static readonly QuoteRepositoryContractResolver Instance = new QuoteRepositoryContractResolver();
  
      protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
      {
          JsonProperty property = base.CreateProperty(member, memberSerialization);
  
          if (property.DeclaringType == typeof(KeyValuePair&lt;IRequest, IQuoteTimeSeries&gt;))
          {
              if (property.PropertyName.Equals("Key", StringComparison.OrdinalIgnoreCase))
              {
                  property.PropertyName = "Request";
              }
              else if (property.PropertyName.Equals("Value", StringComparison.OrdinalIgnoreCase))
              {
                  property.PropertyName = "Data";
              }
          }
          else if (property.DeclaringType == typeof(KeyValuePair&lt;DateTime, IQuote&gt;))
          {
              if (property.PropertyName.Equals("Key", StringComparison.OrdinalIgnoreCase))
              {
                  property.PropertyName = "TimeStamp";
              }
              else if (property.PropertyName.Equals("Value", StringComparison.OrdinalIgnoreCase))
              {
                  property.PropertyName = "Quote";
              }
          }
          return property;
      }
  }
  </code></pre>
  
  <p>The output JSON is odd. The Key and Value items are completely unchanged, even though I did change their names in the code. </p>
  
  <pre><code>[
      {
          "Key": {
              "QuoteDate": "2016-05-12T00:00:00-04:00",
              "QuoteType": "Index",
              "Symbol": "SPY",
              "UseCache": true
          },
          "Value": [
              {
                  "Key": "2016-05-11T16:00:01-04:00",
                  "Value": {
                      "Description": "SPDR S&amp;amp;P 500",
                      "High": 208.54,
                      "Low": 206.50,
                      "Change": -1.95,
                      "ChangePer": -0.94,
                      "Price": 206.50,
                      "QuoteTimeStamp": "2016-05-11T16:00:01-04:00",
                      "Symbol": "SPY"
                  }
              }
          ]
      },
      {
          "Key": {
              "QuoteDate": "2016-05-12T00:00:00-04:00",
              "QuoteType": "Stock",
              "Symbol": "GOOG",
              "UseCache": true
          },
          "Value": [
              {
                  "Key": "2016-05-11T16:00:00-04:00",
                  "Value": {
                      "Description": "Alphabet Inc.",
                      "High": 724.48,
                      "Low": 712.80,
                      "Change": -7.89,
                      "ChangePer": -1.09,
                      "Price": 715.29,
                      "QuoteTimeStamp": "2016-05-11T16:00:00-04:00",
                      "Symbol": "GOOG"
                  }
              }
          ]
      }
  ]
  </code></pre>
  
  <p>Does anyone know how to change the 'Key' and 'Value' items properly​? </p>