title: De-serialising nested child objects when parsing JSON with C# and Linq
body: <p>Is there a better way when querying JSON with C# and Linq, to retrieve the child objects for the following JSON / code?</p>
  
  <p>The object models have a 'Data' class with integer id, string value and 'Item' properties.</p>
  
  <p>The 'Item' class has integer id and string value properties.</p>
  
  <pre><code>{
  "data":[
      {            
          "id" : 123,
          "value" : "Something",
          "childObject":{
              "id" : 345,
              "value" : "Something else",
          },
      },
      {
          "id" : 467,
          "value" : "Nothing",
      }
  ]
  }
  </code></pre>
  
  <p>For the above I am parsing like so:</p>
  
  <pre><code>JObject jsonObj = JObject.Parse(jsonText);
  JArray jsonArr = jsonObj.SelectToken("data") as JArray;
  if (jsonArr.Count == 0)
  {
     return new List&lt;Data&gt;();
  }
  else
  {
     return jsonArr.Select(o =&gt; new Data((int)o["id"], (string)o["value"], o["childObject"] == null ? null : new Item((int)o["childObject"]["id"], (string)o["childObject"]["value"]))).ToList();
  }
  </code></pre>
  
  <p>Were the child object an array of 'Items' I could replace the last Data constructor parameter with something like this:</p>
  
  <pre><code>o["childObject"].Count() == 0 ? 
      new List&lt;Item&gt;() : 
      o["childObject"].Select(i =&gt; new Item((int)i["id"], (string)i["value"]))).ToList()));
  </code></pre>
  
  <p>which reads better to me, though may be no better?</p>
  
  <p>New to LINQ and JSON.NET so all advice welcome.</p>