title: "Cannot access child value on Newtonsoft.Json.Linq.JValue."
body: <p>Sorry if this is a basic one, I'm fairly new to this.</p>
  <p>I have a JObject jObj with JSON data that may or may not have a child object.</p>
  <p><strong>Scenario 1</strong></p>
  <pre><code>  },
    &quot;feedback&quot;: {
      &quot;rating&quot;: false,
      &quot;comment&quot;: &quot;test&quot;
    },
  </code></pre>
  <p><strong>Scenario 2</strong></p>
  <pre><code>  },
    &quot;feedback&quot;: null,
  </code></pre>
  <p>What I am trying to do is handle both scenarios, initially I thought if a child object didn't exist I could evaluate with null but it doesn't appear to be that simple.</p>
  <pre><code>var jObj = (JObject)JsonConvert.DeserializeObject(JSON, new JsonSerializerSettings() { DateParseHandling = DateParseHandling.None });
  
  string rating = (string)jObj[&quot;feedback&quot;][&quot;rating&quot;];
  string rating_comment = (string)jObj[&quot;feedback&quot;][&quot;rating_comment&quot;];
  </code></pre>
  <p>Scenario 1 works a treat but Scenario 2 throws the following exception.</p>
  <blockquote>
  <p>&quot;Cannot access child value on Newtonsoft.Json.Linq.JValue.&quot;</p>
  </blockquote>
  <p>I then tried a different approach in an attempt to evaluate if &quot;feedback&quot; had an object before I referenced the feedback keys.</p>
  <pre><code>JObject jObjFeedback = (JObject)jObj.GetValue(&quot;feedback&quot;);
  bool containsFeedback = jObjFeedback.ContainsKey(&quot;rating&quot;);
  
  if (containsFeedback)
  {
      rating = (string)jObj[&quot;feedback&quot;][&quot;rating&quot;];
      rating_comment = (string)jObj[&quot;feedback&quot;][&quot;rating_comment&quot;];
  }
  else
  {
      log.Info(&quot;No feedback rating found&quot;);
  }
  </code></pre>
  <p>Again this worked fine for Scenario 1 as the feedback object exists, but when it doesn't I get the following exception.</p>
  <blockquote>
  <p>&quot;Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type
  'Newtonsoft.Json.Linq.JObject'&quot;</p>
  </blockquote>
  <p>I'm sure there must be a simple way to handle the two scenarios, unfortunately I can't seem to find it.</p>
  <p>Any help is much appreciated.</p>