title: Detect if deserialized object is missing a field with the JsonConvert class in Json.NET
body: <p>I'm trying to deserialize some JSON objects using Json.NET. I've found however that when I deserialize an object that doesn't have the properties I'm looking for that no error is thrown up but a default value is returned for the properties when I access them. It's important that I'm able to detect when I've deserialized the wrong type of object. Example code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Newtonsoft.Json;
  
  namespace Json_Fail_Test
  {
      class Program
      {
          [JsonObject(MemberSerialization.OptOut)]
          private class MyJsonObjView
          {
              [JsonProperty("MyJsonInt")]
              public int MyJsonInt { get; set; }
          }
  
          const string correctData = @"
          {
              'MyJsonInt': 42
          }";
  
          const string wrongData = @"
          {
              'SomeOtherProperty': 'fbe8c20b'
          }";
  
          static void Main(string[] args)
          {
              var goodObj = JsonConvert.DeserializeObject&lt;MyJsonObjView&gt;(correctData);
              System.Console.Out.WriteLine(goodObj.MyJsonInt.ToString());
  
              var badObj = JsonConvert.DeserializeObject&lt;MyJsonObjView&gt;(wrongData);
              System.Console.Out.WriteLine(badObj.MyJsonInt.ToString());
          }
      }
  }
  </code></pre>
  
  <p>The output of this program is:
  42
  0</p>
  
  <p>I would prefer an exception be thrown to failing silently. Short of that is there a way to detect if the serialization failed to find a parameter?</p>
  
  <p>I know I can parse the data with a Json object and then check for the parameter with a key value lookup but the codebase I'm in uses the pattern above and I'd like keep that consistent if it's possible.</p>