title: Getting nested properties with System.Text.Json
body: <p>I am working with <code>System.Text.Json</code> in my project as I am processing large files so also decided to use it for processing GraphQL responses.</p>
  
  <p>Due to the nature of GraphQL sometimes I get highly nested responses that are not fixed and don't make sense to map to a class.  I usually need to check a few properties on the response.</p>
  
  <p>My issue is with <code>JsonElement</code>. To check nested properties feels very clumsy and I feel like there should be a better way to approach this.</p>
  
  <p>For example take my below code simulating a response I get.  I just want to check if 2 properties exist (id &amp; originalSrc) and if they do get their value but it feels like I have made a meal of the code.  Is there a better/clearer/more succinct way to write this?</p>
  
  <pre><code>var raw = @"{
  ""data"": {
  ""products"": {
      ""edges"": [
          {
              ""node"": {
                  ""id"": ""gid://shopify/Product/4534543543316"",
                  ""featuredImage"": {
                      ""originalSrc"": ""https://cdn.shopify.com/s/files/1/0286/pic.jpg"",
                      ""id"": ""gid://shopify/ProductImage/146345345339732""
                  }
              }
          }
      ]
  }
  }
  }";
  
  var doc = JsonSerializer.Deserialize&lt;JsonElement&gt;(raw);
  
  JsonElement node = new JsonElement();
  
  string productIdString = null;
  
  if (doc.TryGetProperty("data", out var data))
      if (data.TryGetProperty("products", out var products))
          if (products.TryGetProperty("edges", out var edges))
              if (edges.EnumerateArray().FirstOrDefault().ValueKind != JsonValueKind.Undefined &amp;&amp; edges.EnumerateArray().First().TryGetProperty("node", out node))
                  if (node.TryGetProperty("id", out var productId))
                      productIdString = productId.GetString();
  
  string originalSrcString = null;
  
  if(node.ValueKind != JsonValueKind.Undefined &amp;&amp; node.TryGetProperty("featuredImage", out var featuredImage))
      if (featuredImage.TryGetProperty("originalSrc", out var originalSrc))
          originalSrcString = originalSrc.GetString();
  
  if (!string.IsNullOrEmpty(productIdString))
  {
      //do stuff
  }
  
  if (!string.IsNullOrEmpty(originalSrcString))
  {
      //do stuff
  }
  </code></pre>
  
  <p>It is not a crazy amount of code but checking a handful of properties is so common I would like a cleaner more readble approach.</p>