title: Deserializing JSON with Missing Property Names on Response
body: <p>I am trying to deserialize JSON by reading a file. This file will be the same as what I will receive in future requests.  I created classes based on some sample data. However, I am running into trouble with property names that do not appear on every response.  Therefore, I receive an exception which says </p>
  
  <pre><code>"ArgumentException: Could not cast or convert from System.String to object" error.  
  </code></pre>
  
  <p>For example, below is a sample of the JSON I am trying to deserialize.
  My classes are build for this layout</p>
  
  <pre><code>      "contents": [
          {
            "template": "paragraph",
            "title": null,
            "values": [
              {
                "name": null,
                "value": "paragraph of text"
              },
              {
                "name": null,
                "value": "paragraph of text"
              }
            ]
          }
  ]
  </code></pre>
  
  <p>However sometimes I get this as a response.</p>
  
  <pre><code>      "contents": [
          {
            "template": "paragraph",
            "title": null,
            "values": [
              "paragraph of text"
            ]
          }
  ]
  </code></pre>
  
  <p>Notice how the { } and properties "name" and "value" are gone from the "values" array? </p>
  
  <p>Here is my class for the "contents" array</p>
  
  <pre><code>    public class Contents
      {
          public Contents()
          {
              Values = new List&lt;TemplateValue&gt;();
          }
  
          [JsonPropertyName("template")]
          public string Template { get; set; }
  
          [JsonPropertyName("title")]
          public string Title { get; set; }
  
          [JsonPropertyName("values")]
          public List&lt;TemplateValue&gt; Values { get; set; }
      }
  
      public class TemplateValue
      {
          [JsonPropertyName("name")]
          public string Name { get; set; }
  
          [JsonPropertyName("value")]
          public string Value { get; set; }
      }
  </code></pre>
  
  <p>Here is how I am deserializing the file</p>
  
  <pre><code>var jsonString = File.ReadAllText(_jsonFilelocation);
  var jsonObject = JsonConvert.DeserializeObject&lt;Contents&gt;(jsonString);
  </code></pre>
  
  <p>How can I adjust my code to fix this type of scenario?  Thanks in advance for any help!</p>