using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
JObject json = JObject.Parse(GetJson());
string[] tableNames = {"TableStart:equipment:defectNow:Filter:defect_type=DN","TableStart:equipment:defectFuture:Filter:defect_type=DF","TableStart:equipment:defectNone"};
List<JObject> test = new List<JObject>();
for (int j = 0; j <= 2; j++)
string[] tableNameParts = tableNames[j].Split(':');
string tableNameJson = tableNameParts[1].Replace("»", "");
var jsonRows = json[tableNameJson];
if (tableNameParts.Count() > 3)
if (tableNameParts[3].Replace("»", "").ToLower() == "filter" && tableNameParts.Count() > 4)
string[] FilterParts = tableNameParts[4].Split('=');
if (FilterParts.Count() > 1)
string FilterField = FilterParts[0].Replace("»", "");
string FilterValue = FilterParts[1].Replace("»", "");
JArray filteredArray = new JArray();
if (jsonRows[0].GetType() == typeof(JObject))
foreach (JObject arrayObject in jsonRows)
foreach (var objectItem in arrayObject)
string objectItemValue = string.Empty;
if (objectItem.Value.GetType() == typeof(JArray))
foreach (var item in objectItem.Value)
objectItemValue = (string)objectItem.Value;
if (objectItem.Key == FilterField && objectItemValue == FilterValue)
filteredArray.Add(arrayObject);
foreach (JArray arrayGroup in jsonRows)
foreach (JObject arrayObject in arrayGroup)
foreach (var objectItem in arrayObject)
string objectItemValue = string.Empty;
if (objectItem.Value.GetType() == typeof(JArray))
foreach (var item in objectItem.Value)
objectItemValue = (string)objectItem.Value;
if (objectItem.Key == FilterField && objectItemValue == FilterValue)
filteredArray.Add(arrayObject);
jsonRows = filteredArray;
JArray singleArray = new JArray();
foreach(var arraySet in jsonRows)
if (!test.Contains(arraySet))
if (arraySet.GetType() == typeof(JObject))
singleArray.Add(arraySet);
foreach (JObject arrayObject in arraySet)
singleArray.Add(arrayObject);
Console.WriteLine("");Console.WriteLine("");Console.WriteLine("");
Console.WriteLine(tableNameParts[2]);
static string GetJson() => @" {
""date_of_examination"": ""2022-05-20T14:08:38.072965"",
""defect_type"": [""DN""],
""eqpt_name"": [""2 Leg Chain Sling""],
""eqpt_manufacturer"": ""Merc"",
""eqpt_model"": ""edes"",
""exam_type"": [""6 Months""],
""date_of_last_examination"": ""2021-11-20T00:00:00"",
""date_of_next_examination"": ""2022-11-20T00:00:00"",
""defect"": ""sling is torn"",
""action_required"": ""replace""
""date_of_examination"": ""2022-05-20T14:12:23.997004"",
""eqpt_name"": [""Other - ""],
""eqpt_name_other"": ""widget"",
""eqpt_manufacturer"": ""merc"",
""eqpt_model"": ""edes"",
""exam_type"": [""6 Months""]
""date_of_examination"": ""2022-05-20T14:13:24.795136"",
""defect_type"": [""DF""],
""eqpt_name"": [""Endless Round Sling (2.5m)""],
""eqpt_manufacturer"": ""merc"",
""eqpt_model"": ""edes"",
""exam_type"": [""6 Months""],
""defect"": ""stitching is coming undone"",
""danger_units"": [""Weeks""],
""action_required"": ""needs to be stitched again""
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version);
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Assembly.GetName().Name, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");