title: Json.NET - Custom deserialization of multiple object properties to list of single type?
body: <p>I've been trying to come up with the simplest/cleanest method for handling this and after several refactors am no closer. I am hoping someone here can assist.</p>
  
  <p>The JSON returned from the service I am calling is unpredictable and constantly updates.</p>
  
  <p>Example:</p>
  
  <pre><code>{
      SomeKey : "SomeValue",
      SecondaryProperties: {
          Property1: { "Id" : "ABC", "Label" : "Property One", "Value" : 1 },
          Property2: { "Id" : "DEF", "Label" : "Property Two", "Value" : 10 },
          Property3: { "Id" : "GHI", "Label" : "Property Three", "Value" : 5 },
          Banana: { "Id" : "YUM", "Label" : "Property Four", "Value" : 5 },
          WeJustAddedThis: { "Id" : "XYZ", "Label" : "Property Five", "Value" : 1 }
      }
  }
  </code></pre>
  
  <p>Since these secondary property keys are constantly changing (note: the values are always consistent thankfully!), it makes little sense to create an object with properties for each as I'd be updating the object often and unless I was told a new data point was added to the API data, it would never appear in the application until the code was updated.</p>
  
  <p>So I had a thought to create a custom attribute converter that would make a list of a <code>SecondaryProperty</code> object. Something like:</p>
  
  <pre><code>public class SecondaryProperties {
      public string SomeKey { get; set; }
      [JsonConverter(typeof(SecondaryPropertyConverter))]
      public List&lt;SecondaryProperty&gt; PropertyList { get; set; }
  }
  
  public class SecondaryProperty {
      public string Id { get; set; }
      public string Label { get; set; }
      public int Value { get; set; }
  }
  
  // This is where things get hazy for me
  public class SecondaryPropertyConverter: JsonConverter {
      ...
      public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
          var ratings = new List&lt;SecondaryProperty&gt;();
          var obj = JObject.Load(reader);
          foreach(var property in obj.Properties()){
              var rating = property.Value&lt;SecondaryProperty&gt;();
              ratings.Add(rating);
          }
          return ratings;
      }  
  }
  </code></pre>
  
  <p>I think I'm on the right track, but the list is always null, so clearly I'm missing something. Can anyone provide some insight?</p>
  
  <p>Many thanks!</p>