title: Querying and Filtering Array of JObjects with Linq
body: <p>I suppose this is another entry in my series of questions, but I'm stuck again. This time, I'm having trouble working with a JArray of JObjects and determining the Property.Value type for each element in the JArray... </p>
  
  <p>My code is here:
  <a href="https://dotnetfiddle.net/bRcSAQ" rel="nofollow">https://dotnetfiddle.net/bRcSAQ</a></p>
  
  <p>The difference between my previous questions and this question is that my outer Linq query gets both JObject and JArray tokens, so that's why I have an <code>if (jo is JObject)</code> at Line 40 and a <code>if (jo is JArray)</code> at Line 48. </p>
  
  <p>Once I know I have a JArray of <code>&lt;JObjects&gt;</code>, I have code that looks like this (Lines 48-):</p>
  
  <pre><code>    if (jo is JArray)
      {
          var items = jo.Children&lt;JObject&gt;();                     
          // return a JObject object
      }
  </code></pre>
  
  <p>When I use a debugger and look at items, I see that it contains 3 JObject objects--one for Item_3A1, Item_3A2, and Item3A3. But I need to know the JTokenType for each JProperty.Value because I am interested only in Property values of type JTokenType.String.</p>
  
  <p>So I tried:</p>
  
  <pre><code>// doesn't work :(
  var items = jo.Children&lt;JObject&gt;()
                .Where(p =&gt; p.Value.Type == JTokenType.String);
  </code></pre>
  
  <p>The compiler red-lines the Value property with the error <code>CS0119 'JToken.Value&lt;T&gt;(object)' is a method, which is not valid in the given context.</code></p>
  
  <p>I realize that "p" in the Linq express is not a JProperty. I guess it's a JObject. And I don't know how to cast "p" so that I can examine the type of JProperty object it represents. </p>
  
  <p>Ultimately, I need the code for JArray processing (starting at Line 48) to add an return a JObject that contains an JSON array composed only of JProperty objects of type JTokenType.String. This means that given the sample JSON, it first should return a JObject holding these JSON properties:</p>
  
  <pre><code>{ ""Item_3A1"": ""Desc_3A1"" },
  { ""Item_3A2"": ""Desc_3A2"" },
  { ""Item_3A3"": ""Desc_3A3"" }
  </code></pre>
  
  <p>On the next iteration, it should return a JObject holding these JSON properties (notice that the nested Array3B1 properties are omitted because Array3B1 is not a JProperty with a Value type of JTokenType.String):</p>
  
  <pre><code>{ ""Item_3B1"": ""Desc_3B1"" },
  { ""Item_3B2"": ""Desc_3B2"" },
  </code></pre>
  
  <p>The third iteration would contain:</p>
  
  <pre><code>{ ""Item_3B11"": ""Desc_3B11"" },
  { ""Item_3B12"": ""Desc_3B12"" },
  { ""Item_3B13"": ""Desc_3B13"" }
  </code></pre>
  
  <p>And the fourth (final) iteration would contain:</p>
  
  <pre><code>{ ""Item_3C1"": ""Desc_3C1"" },
  { ""Item_3C2"": ""Desc_3C2"" },
  { ""Item_3C3"": ""Desc_3C3"" }
  </code></pre>
  
  <p>This might be my final hurdle in this "series". </p>
  
  <p>Sincere thanks to anyone who can and will help--and a special thanks again to users "Brian Rogers" and "dbc" for their truly amazing JSON.NET/Linq knowledge.</p>