-1

I have a large JSON file ( about 1.5 Gigabytes) and I want to convert it to DataTable. But I want to do is that first I should read it then DeserializeObject to DataTable. Here is my code:

StreamReader read = new StreamReader(@"C:\Users\Reza\Downloads\yelp_dataset_challenge_academic_dataset\yelp_dataset_challenge_academic_dataset\yelp_dataset_challenge_academic_dataset\yelp_academic_dataset_review.json");
        string json = read.ReadToEnd();        
        DataTable tester = JsonConvert.DeserializeObject<DataTable>(json);
        dataGridView1.DataSource = tester;

But this code give me error and shows System.OutOfMemoryException What should i do?

iYoung
  • 3,596
  • 3
  • 32
  • 59
Reza Tanzifi
  • 572
  • 4
  • 13
  • 1
    possible duplicate of [Incremental JSON Parsing in C#](http://stackoverflow.com/questions/9026508/incremental-json-parsing-in-c-sharp) – Craig W. May 02 '15 at 14:20
  • 1
    See here: http://stackoverflow.com/questions/27315521/system-outofmemoryexception-with-json-net-with-listobject and here: http://stackoverflow.com/questions/20374083/deserialize-json-array-stream-one-item-at-a-time – dbc May 03 '15 at 03:04

1 Answers1

0

From what I see by looking at the JsonConvert methods, it does not contain one that accepts a stream as input - there seem to be strings only. So - bad news - it won't be straightforward.

You may need to somehow divide the string into smaller chunks and then convert these.

I've found an article that describes similar process here:

http://www.drdobbs.com/windows/parsing-big-records-with-jsonnet/240165316?pgno=1

Piotr Piotr
  • 213
  • 2
  • 7
  • Thanks for your answer, but it does not matter that you use Stream or string, i use string x = File.ReadAllText() too, but because of the size,it gives me the error. – Reza Tanzifi May 02 '15 at 14:09
  • Yes,my requirement is the same to read all at once and foram dataset with tables and create SQL tables.. but its is throwing out of memory exception.. Please advise.. – user1046415 Jul 26 '16 at 16:14