title: JContainer, JObject, JToken and Linq confusion
body: <p>I am having trouble understanding when to use <code>JContainer</code>, <code>JObject</code>, and <code>JToken</code>. I understand from the "standards" that <code>JObject</code> is composed of <code>JProperties</code> and that <code>JToken</code> is the base abstract class for all of the <code>JToken</code> types, but I don't understand <code>JContainer</code>.</p>
  
  <p>I am using C# and I just bought LinqPad Pro 5. </p>
  
  <p>I have a JSON data source in a file, so I'm deserializing that file's contents successfully using this statement:</p>
  
  <pre><code>string json;
  using (StreamReader reader = new StreamReader(@"myjsonfile.json"))
  {
      json = reader.ReadToEnd();
  }
  </code></pre>
  
  <p>At that point, I take the JSON string object and deserialize it to a <code>JObject</code> (and this might be my mistake--perhaps I need to make <code>jsonWork</code> a <code>JToken</code> or <code>JContainer</code>?):</p>
  
  <pre><code>JObject jsonWork = (JObject)JsonConvert.DeserializeObject(json);
  </code></pre>
  
  <p>In my JSON data (the string represented by JSON), I have three objects--the top-level object look similar to this:</p>
  
  <pre><code>{
    "Object1" : { ... },
    "Object2" : { ... },
    "Object3" : { ... }
  }
  </code></pre>
  
  <p>Each object is composed of all sorts of tokens (arrays, strings, other objects, etc.), so it is dynamic JSON. (I used ellipses as placeholders rather than muddying up this question wit lots of JSON data.) </p>
  
  <p>I want to process <code>"Object1"</code>, <code>"Object2"</code>, and <code>"Object3"</code> separately using LINQ, however. So, ideally, I would like something like this:</p>
  
  <pre><code>// these lines DO NOT work    
  var jsonObject1 = jsonWork.Children()["Object1"]
  var jsonObject2 = jsonWork.Children()["Object2"]
  var jsonObject3 = jsonWork.Children()["Object3"]
  </code></pre>
  
  <p>But the above lines fail.</p>
  
  <p>I used <code>var</code> above because I have no idea what object type I should be using: <code>JContainer</code>, <code>JObject</code>, or <code>JToken</code>! Just so you know what I want to do, once the above <code>jsonObject#</code> variables are properly assigned, I would like to use LINQ to query the JSON they contain. Here is a very simple example:</p>
  
  <pre><code>var query = from p in jsonObject1
     where p.Name == "Name1"
     select p
  </code></pre>
  
  <p>Of course, my LINQ ultimately will filter for JSON arrays, objects, strings, etc., in the <code>jsonObject</code> variable. I think once I get going, I can use LinqPad to help me filter the JSON using LINQ.</p>
  
  <p>I discovered that if I use: </p>
  
  <pre><code>// this line WORKS 
  var jsonObject1 = ((JObject)jsonWork).["Object1"];
  </code></pre>
  
  <p>Then I get an <code>JObject</code> type in <code>jsonObject1</code>. Is this the correct approach? </p>
  
  <p>It is unclear to me when/why one would use <code>JContainer</code> when it seems that <code>JToken</code> and <code>JObject</code> objects work with LINQ quite well. What is the purpose of <code>JContainer</code>?</p>