I'm trying to fetch the values from the key/value pairs shown within the inner brackets inside the rows[]
The class I use to de-serialize the JSON object does not contain individual values given they may change between different data sets.
JSON Object looks like this:
{
"columns": [
"(Column 1)",
"@Level",
"@Exception",
"@Properties"
],
"rows": [
[
"2020-09-09T19:04:54.8422073Z",
"Information",
null,
{
"LogEventCategory": "System",
"LogEventType": "Application Startup",
"LogEventSource": "",
"LogUserId": "",
"LogUsername": "",
"LogForename": "",
"LogSurname": "",
"LogData": "Application Starting Up",
"MachineName": "DESKTOP-OS52032",
"ProcessId": 16608,
"ThreadId": 1,
"ApplicationSource": "WebApp-RAZOR"
}
],
[
"2020-09-09T19:09:06.5560521Z",
"Information",
null,
{
"LogEventCategory": "System",
"LogEventType": "Application Startup",
"LogEventSource": "",
"LogUserId": "",
"LogUsername": "",
"LogForename": "",
"LogSurname": "",
"LogData": "Application Starting Up",
"MachineName": "DESKTOP-OS52032",
"ProcessId": 15588,
"ThreadId": 1,
"ApplicationSource": "WebApp-RAZOR"
}
],
"statistics": {
"scannedEventCount": 11,
"matchingEventCount": 6,
"uncachedSegmentsScanned": false,
"elapsedMilliseconds": 0.1267
}
}
The values I'm trying to fetch are the ones listed:
"LogEventCategory": "System",
"LogEventType": "Application Startup",
"LogEventSource": "",
"LogUserId": "",
"LogUsername": "",
"LogForename": "",
"LogSurname": "",
"LogData": "Application Starting Up",
"MachineName": "DESKTOP-OS52032",
"ProcessId": 16608,
"ThreadId": 1,
"ApplicationSource": "WebApp-RAZOR"
When looping through the JSON object, I want to retrieve the values using some form of LINQ query or similar.
So far I've only been able to retrieve the first level items:
foreach (var item in logs.Rows)
{
Timestamp = DateTime.Parse(item.First().ToString()), // = "2020-09-09T19:04:54.8422073Z"
Level = item.Skip(1).First().ToString(), // = "Information"
Exception = (item.Skip(2).First() ?? "-").ToString(), // = "-" in this example becuase json value is null
}
Class for de-serializing the JSON:
public class QueryLogEvents
{
[JsonProperty("columns")]
public string[] Columns { get; set; }
[JsonProperty("rows")]
public object[][] Rows { get; set; }
[JsonProperty("statistics")]
public Statistics Statistics { get; set; }
}
public class Statistics
{
[JsonProperty("scannedEventCount")]
public int ScannedEventCount { get; set; }
[JsonProperty("matchingEventCount")]
public int MatchingEventCount { get; set; }
[JsonProperty("uncachedSegmentsScanned")]
public bool UncachedSegmentsScanned { get; set; }
[JsonProperty("elapsedMilliseconds")]
public float ElapsedMilliseconds { get; set; }
}
Rowsas List<dynamic> and casting elements as needed, like stackoverflow.com/questions/29459064/…