title: Parsing large JSON file in .NET
body: <p>I have used the "JsonConvert.Deserialize(json)" method of Json.NET so far which worked quite well and to be honest, I didn't need anything more than this.</p>
  
  <p>I am working on a background (console) application which constantly downloads the JSON content from different URLs, then deserializes the result into a list of .NET objects.</p>
  
  <pre><code> using (WebClient client = new WebClient())
   {
        string json = client.DownloadString(stringUrl);
  
        var result = JsonConvert.DeserializeObject&lt;List&lt;Contact&gt;&gt;(json);
  
   }
  </code></pre>
  
  <p>The simple code snippet above doesn't probably seem perfect, but it does the job. When the file is large (15,000 contacts - 48 MB file), JsonConvert.DeserializeObject isn't the solution and the line throws an exception type of JsonReaderException.</p>
  
  <p>The downloaded JSON content is an array and this is how a sample looks like. Contact is a container class for the deserialized JSON object.</p>
  
  <pre><code>[
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    }
  ]
  </code></pre>
  
  <p>My initial guess is it runs out of memory. Just out of curiosity, I tried to parse it as JArray which caused the same exception too.</p>
  
  <p>I have started to dive into Json.NET documentation and read similar threads. As I haven't managed to produce a working solution yet, I decided to post a question here.</p>
  
  <p>UPDATE: While deserializing line by line, I got the same error: " [. Path '', line 600003, position 1." So downloaded two of them and checked them in Notepad++. I noticed that if the array length is more than 12,000, after 12000th element, the "[" is closed and another array starts. In other words, the JSON looks exactly like this:</p>
  
  <pre><code>[
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    }
  ]
  [
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    },
    {
      "firstname": "sometext",
      "lastname": "sometext"
    }
  ]
  </code></pre>