title: Parse large JSON file with the bulk of the data inside a property of the root object
body: <p>I'm working on parsing a relatively large (1.01GB) JSON file using the JSON.NET framework that is structured like below:</p>
  
  <pre><code>{
    "Stores": [
      {
          "Number": 1234,
          "City": "Denver",
          "County": "Denver",
          "Departments": [
              {
                  "Name": "Deli",
                  "Description": "sliced lunchmeat"
              },
              {
                  "Name": "Produce",
                  "Description": "fruit and vegetables"
              }
          ],
          "Telephone": "555-1212"
      },
      {
          "Number": 5678,
          "City": "Parker",
          "County": "Douglas",
          "Departments": [
              {
                  "Name": "Seafood",
                  "Description": "creatures of the sea"
              },
              {
                  "Name": "Meat",
                  "Description": ""
              }
          ],
          "Telephone": "555-2323"
      }
    ]
  }
  </code></pre>
  
  <p>I attempted to parse the whole JSON file at once, but ran into out-of-memory exceptions, so I am now trying to parse the file in chunks. I'm able to get it working using the code below, but only if I remove the root Stores object. The actual file that I have to parse has the root Stores object, so I need to figure out how to get this to work. I'm relatively new to JSON, so any help would be greatly appreciated. Thanks.</p>
  
  <pre><code>using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
  using (StreamReader sr = new StreamReader(fs))
  using (JsonTextReader reader = new JsonTextReader(sr))
  {
      while (reader.Read())
      {
          DepartmentInfo = "";
  
          if (reader.TokenType == JsonToken.StartObject)
          {
              dynamic obj = JObject.Load(reader);
  
              City = obj.City.ToString();
              County = obj.County.ToString();
  
              foreach (var Department in obj.Departments)
              {
                  DepartmentInfo += Department.ToString();
              }
          }
      }
  }
  </code></pre>
  
  <p>UPDATE: I updated the JSON to show the actual format I'm working with, it was missing a Description field in the Departments array. Also a little more context on what I'm doing - I'm loading this file into a database, and have a requirement to keep it looking as close to the source as possible so it can be tracked, and then further processing occurs in the database to normalize the data into another data model, so the DepartmentInfo is kind of gnarly by design. The final code is below.  Thanks!</p>
  
  <pre><code>string DepartmentInfo = "";
  
  using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
  using (StreamReader sr = new StreamReader(fs))
  using (JsonTextReader reader = new JsonTextReader(sr))
  {
      while (reader.TokenType != JsonToken.StartArray)
          reader.Read();
  
      while(reader.Read())
      {
          DepartmentInfo = "";
  
          if (reader.TokenType == JsonToken.StartObject)
          {
              dynamic obj = JObject.Load(reader);
  
              var StoreNumber = obj["Number"];
              var City = obj["City"].ToString();
              var County = obj["County"].ToString();
              var PhoneNumber = obj["Telephone"];
  
              foreach (var Department in obj.Departments)
              {
                  DepartmentInfo += ("Name: " + Department.Name.ToString() + ", Description: " + Department.Description.ToString() + " ");
              }
  
  
          }
      }
  }
  </code></pre>