I know how to convert a json data into datatable, here I need to know if there is any formula to get the expected datatable row without actually converting the json into datatable.
Asked
Active
Viewed 161 times
-1
-
I think this is helpful for you. [show](https://stackoverflow.com/questions/11138035/convert-datatable-to-json-with-key-per-row) – Vishal Parmar Oct 31 '18 at 04:45
-
it would be very helpful to edit you question with the additional information of the bounty (getting memory exceptions etc.) – Falco Alexander Nov 02 '18 at 09:41
-
there will be a lot of very similar questions in SO, please check and the links included there https://stackoverflow.com/questions/43747477/how-to-parse-huge-json-file-as-stream-in-json-net for processing huge JSONs as a stream and other workarounds. – Falco Alexander Nov 02 '18 at 09:49
2 Answers
1
as already commented, parse the big JSON as a stream to handle huge amounts. Then it's up to you to count the rows or process it to DataTables without memory exceptions:
using (FileStream s = File.Open("big.json")) // or any other stream
using (StreamReader streamReader = new StreamReader(s))
using (JsonTextReader reader = new JsonTextReader(streamReader))
{
reader.SupportMultipleContent = true;
int rowCount = 0;
var serializer = new JsonSerializer();
while (reader.Read())
{
if (reader.TokenType == JsonToken.StartObject)
{
DataRow r = serializer.Deserialize<Contact>(reader);
rowCount++;
}
}
}

Falco Alexander
- 3,092
- 2
- 20
- 39
-
2You don't need to deserialize the current row (which you are doing via `DataRow r = serializer.Deserialize
(reader);`). You just need to *skip it* so that child objects are not counted as table rows. [`JsonReader.Skip()`](https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_JsonReader_Skip.htm) should do the job. – dbc Nov 03 '18 at 06:07
0
You can filter using JObject
using this way
string jsonData = "";
using (StreamReader reader = new StreamReader("big.json"))
{
jsonData = reader.ReadToEnd();
reader.Close();
}
JObject o = JObject.Parse(jsonData);
var results = o["datatable"].Where(x => (bool)x["filter"]).ToArray();

Baskar John
- 726
- 5
- 9